我是CodeQL的新手,已经开始学习C/C++程序的数据流查询.以下是我想分析的一个C程序的摘录:
int main(int argc, char * argv[])
{
unsigned short size, x, y;
int r1, r2;
x = atoi(argv[1]);// one dim of the data
y = atoi(argv[2]);//other dim of the data
size = x*y; //total size of the data
r1 = MyVuln(size*sizeof(char));
r2 = MyVuln(x*sizeof(char));
...
// some code
...
return 0
}
在上面的例子中,我想要捕获使用size
作为参数调用MyVuln
函数的情况.size
被定义为AssignExpr
的结果,使得其Rvalue
是乘法的结果.以下是我编写的COdeQL查询:
/*
@kind path-problem
*/
import cpp
import semmle.code.cpp.dataflow.new.DataFlow
//import DataFlow::PathGraph
from Function myvuln, FunctionCall fc, AssignExpr ab
where
myvuln.hasGlobalName("MyVuln")
and fc.getTarget() = myvuln
and ab.getLValue().getType().getUnspecifiedType() instanceof IntegralType
and ab.getRValue() instanceof MulExpr
and exists (DataFlow::Node src, DataFlow::Node sink|
src.asExpr() = ab.getLValue()
and sink.asExpr() = fc.getArgument(0)
and DataFlow::localFlow(src, sink)
)
select fc, "MyVuln with Arithmetic arg at " + fc.getLocation().toString()
查询不返回任何结果(我将CodeQl与VS Code一起使用).我还判断了一个较小的部分查询是否可以检测到对应于size
清晰度的表达式,并且它正在工作.我还判断了查询是否找到了对MyVuln的调用,并且它正在工作.只有当我开始编写数据流路径查询时,我才会得到任何结果.这种类型的查询似乎非常直接,但我没有得到任何线索,我在哪里出错了,或者我在这个查询中遗漏了什么.一个帮助就是高度的感激.
谢谢