Monday, December 24, 2012

Secure Coding

Korean Software Companies for Secure Coding Solution

- 파수닷컴
   : 스패로우SCE
- 지티원
   : 시큐리티프리즘
- 트리니티소프트
   : 코드레이
- 이븐스타
- 소프트4소프트
- 지티원

Foreign Companies

- HP
   : 포티파이

Ref. http://www.zdnet.co.kr/news/news_view.asp?artice_id=20121009082634

Tuesday, December 11, 2012

PMD

PMD is a static code analyzer for Java. It allows a developer team to maintain its software  consistently with their prescribed coding guidelines by automatically checking the guidelines against the software.

PMD is flexible since one can easily add new rules simply by writing XPath expressions over Java AST(abstract syntax tree), or more seriously by writing Java codes to detect more complicated inconsistency.

A quick start is possible:

  - Download from http://pmd.sourceforge.net
  - Unzip it, creating a directory named
  - Add the binary directory to your executable path such as PATH.
  - Create a test java file:
      public class Test
     {
        void foo()
        {
            int x = 42;
        }
      }
  - Run PMD on Windows by
 
       C:\> pmd.bat -d Test.java -f text -R rulesets/java/unusedcode.xml
   
     to see the analysis result:

       Test.java:5   Avoid unused local variables such as 'x'.

  - That's it!

You can find much more and more information in the PMD web site, http://pmd.sourceforge.net.

Also, WIKI is always our friend. http://en.wikipedia.org/wiki/PMD_(software).


Sunday, December 09, 2012

If-Else Vs. If

A couple of weeks ago, my friends raised a question as this. Is is harmful to have a use of If without Else? As soon as I saw the question, I answered Yes, because I am a functional programmer. Generally, there is no use of IF without ELSE in functional programming languages.

I'd like to argue why IF had better be paired with ELSE. Let us consider a little code as:

 (1)     if ( cond ) x = e1;  else x = e2;          // in the C programming language
                                                                // e1 and e2 are assumed to be free from side-effects.

One could rewrite (1) as follows:

 (2)     x = e2;   if ( cond ) x = e1;

Actually, (1) and (2) are equivalent to each other; In (2), the IF can be regarded as one with ELSE. Therefore, this pattern of the use of IF is satisfactory.

The last code pose some problem that I will explain.

 (3)     if ( cond ) x = e1;

If the cond evaluates to false, it is unknown
  - whether x is initialized properly, and
  - what value x is initialized with

To know what are unknown stated above, one must examine the context where the code (3) is used. Otherwise, you can't understand what will happen on the negative condition.

One can understand the meaning of (1) locally, just by looking at the code itself, while he or she cannot understand (2) locally because the meaning of (2) depends on the context surrounding it. The local understanding is better than the non-local understanding. This is the reason why IF-ELSE is preferable to IF unpaired with ELSE.

If you are still not so convinced of the advantages of the use of the IF-ELSE pair, you may choose the following option:

 (4)   if ( cond ) x = e;   /* no else */

The comment following the IF explicitly states that the programmer knows that he or she omits ELSE intentionally, not accidentally.


I am curious about other's opinions. Please leave your comments.