2012-10-15 170 views
4

我在java項目上使用「HP Fortify v3.50」,並發現很多關於「空取消引用」的誤報,因爲Fortify沒有看到控制空值是另一種方法。 如何減少誤報並保持規則?如何在Fortify中避免誤報「空取消引用」錯誤

這裏有一個POC

public class MyClass { 
    public static void main(String[] args) { 
     String string01 = null; 
     String string02 = null;  
     int i; 

     if (args[0].equals("A")) { 
      string01 = "X"; 
      string02 = "Y"; 
     } 

     if (!isNull(string02)){ 
      i = string02.length();} //False Positive 
     else { 
      i = string02.length(); 
     } // Yes, it is an error! 
    } 

    public static boolean isNull(Object toBeTested){ 
     return (null == toBeTested);   
    } 
} 

結果:

[E8837DB548E01DB5794FA71F3D5F51C8 : medium : Null Dereference : controlflow ] 
    MyClass.java(13) : Assigned null : string02 
    MyClass.java(16) : Branch not taken: (!args[0].equals("A")) 
    MyClass.java(20) : Branch taken: (!isNull(string02))   //False Positive 
    MyClass.java(21) : Dereferenced : string02 

[E8837DB548E01DB5794FA71F3D5F51C9 : medium : Null Dereference : controlflow ] 
    MyClass.java(13) : Assigned null : string02 
    MyClass.java(16) : Branch not taken: (!args[0].equals("A")) 
    MyClass.java(20) : Branch not taken: isNull(string02) 
    MyClass.java(23) : Dereferenced : string02 

回答

0

這看起來更像是你應該考慮到他們的支持團隊的SCA問題。或者只是審計它不是一個問題。這不是可以通過自定義規則解決的問題。