2017-08-01 77 views
0

我使用Fortify掃描我的代碼後,出現「不安全的JNI(輸入驗證和表示,語義)」問題。我提到了Fortify的建議,並在網站上搜索了一些解決方案,但我無法解決這個問題。在Android Studio中強化掃描問題

我遵循Fortify在website推薦的兼容解決方案。 我甚至使用Fortify從網站掃描推薦的代碼,並得到相同的問題。

我的代碼如下所示:

public final class JNI_Related { 

// JNI 
public native FileDescriptor open(String path, int baudrate, int data_bits, char parity, int stop_bits); 

public native void close(); 

public FileDescriptor DoOpen(String mPath, int mBaudrate, int mData_bits, char mParity, int mStop_bits){ 

    if(mmPath.length() == 0){ 
     throw new NullPointerException(); 
    } 

    if((mmBaudrate < 0) || (mmData_bits < 0) || (mmStop_bits < 0) || (mmParity == 'a')){ 
     throw new IllegalArgumentException(); 
    } 
    mFd = open(mmPath, mmBaudrate, mmData_bits, mmParity, mmStop_bits); 

    if(mFd == null){ 
     throw new IllegalArgumentException(); 
    } 
    return mFd; 
} 

public void DoClose(){ 
    close(); 
} 

static { 
    System.loadLibrary("jniutill"); 
} 

}

我真的需要一些幫助!

+0

您是否曾經爲此找到答案? –

回答

0

在你的本地方法,你有他們聲明爲public

public native FileDescriptor open(...); 
public native void close(); 

你在你的問題鏈接到該網站說,爲了解決這個不安全JNI問題,native方法必須標記爲private ,使您能夠達到native方法的唯一方法是通過您的public包裝方法來清理輸入參數。

+0

感謝您的回覆。在我將公衆更改爲私人後,我得到了同樣的Fortify問題。 @ user1684458 –