C 夹板如何进行污染分析
如何使用夹板进行污染分析 我已经在我的Ubuntu 12.04上安装了Splint。创建了一个小测试用例,如下所示:C 夹板如何进行污染分析,c,analysis,static-code-analysis,splint,taint,C,Analysis,Static Code Analysis,Splint,Taint,如何使用夹板进行污染分析 我已经在我的Ubuntu 12.04上安装了Splint。创建了一个小测试用例,如下所示: #include<stdio.h> #include<string.h> int main(int argc, char *argv[]) { char a[10]; strncpy(a,argv[1],10); printf(a); return 0; } 还创建了splint.mts文件,包含以下内容: int pri
#include<stdio.h>
#include<string.h>
int main(int argc, char *argv[]) {
char a[10];
strncpy(a,argv[1],10);
printf(a);
return 0;
}
还创建了splint.mts文件,包含以下内容:
int printf (/*@untainted@*/ char *fmt, ...);
char *fgets (char *s, int n, FILE *stream) /*@ensures tainted s@*/ ;
char *strcat (/*@returned@*/ char *s1, char *s2) /*@ensures s1:taintedness = s1:taintedness | s2:taintedness @*/ ;
void strncpy (/*@returned@*/ char *s1, char *s2, size_t num) /*@ensures s1:taintedness = s1:taintedness | s2:taintedness @*/ ;
attribute taintedness
context reference char *
oneof untainted, tainted
annotations
tainted reference ==> tainted
untainted reference ==> untainted
transfers
tainted as untainted ==> error "Possibly tainted storage used where untainted required."
merge
tainted + untainted ==> tainted
defaults
reference ==> tainted
literal ==> untainted
null ==> untainted
end
最后,使用以下命令运行夹板工具:
splint -mts splint prg001.c
其中prg001.c是示例输入,“splint”指splint.mts和splint.xh文件。所有文件都在当前目录中
我收到的输出是:
夹板3.1.2——2012年8月21日
prg001.c:(在主功能中)
prg001.c:6:1:printf的格式字符串参数不是编译时常量:
A.
格式参数在编译时未知。这可以带来安全
漏洞,因为无法对参数进行类型检查。(使用
-formatconst(禁止警告)
prg001.c:3:14:未使用参数argc
函数体中未使用函数参数。如果争论
是类型兼容性或未来计划所必需的,请在中使用/@unused@/
参数声明。(使用-参数用于禁止警告)
已完成检查---2个代码警告
输出中没有任何污染分析的迹象。有人能帮我用夹板做污染分析吗
谢谢问题出在splint.xh文件上 我把printf改为printfxxx,效果很好
这意味着标准定义正在覆盖我的.xh文件。这解决了我的问题,现在夹板输出污染变量和污染流 我还通过从fgets函数向char数组中输入并打印它来进行测试。但是输出没有关于splint.xh文件问题的线索。我把printf改为printfxxx,效果很好。这意味着标准定义正在覆盖我的.xh文件。这解决了我的问题