在使用Fortify 扫描代码后,我收到"不安全的 JNI(输入验证和表示,语义("问题。我已经参考了Fortify的建议并在网站上搜索了一些解决方案,但我无法解决问题。
我遵循本网站中强化推荐的合规解决方案。 我什至使用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");
}
}
我真的需要一些帮助!
在本机方法中,将它们声明为public
:
public native FileDescriptor open(...);
public native void close();
您在问题中链接到的站点说,为了解决不安全的JNI问题,必须将native
方法标记为private
,因此您可以访问native
方法的唯一方法是通过清理输入参数的public
包装器方法。