Skip to content

Commit afe4a84

Browse files
authored
Using globalValueNumber to match same arguments
1 parent d476493 commit afe4a84

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-362/double-fetch.ql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@
1515
*/
1616

1717
import cpp
18+
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
1819

1920
class CopyFromUserFunctionCall extends FunctionCall{
2021
CopyFromUserFunctionCall(){
2122
this.getTarget().getName() = "copy_from_user"
2223
and not this.getArgument(1) instanceof AddressOfExpr
2324
}
2425

25-
predicate hasSameArguments(CopyFromUserFunctionCall another){
26+
/*predicate hasSameArguments(CopyFromUserFunctionCall another){
2627
this.getArgument(0).toString() = another.getArgument(0).toString()
2728
and this.getArgument(1).toString() = another.getArgument(1).toString()
29+
}*/
30+
31+
predicate hasSameArguments(CopyFromUserFunctionCall another) {
32+
globalValueNumber(this.getArgument(0)) = globalValueNumber(another.getArgument(0))
33+
and globalValueNumber(this.getArgument(1)) = globalValueNumber(another.getArgument(1))
2834
}
2935

3036
}
@@ -38,11 +44,12 @@ where
3844
and ifStmt.getBasicBlock().getAFalseSuccessor*() = p2.getBasicBlock()
3945
)
4046
and not exists(AssignPointerAddExpr assignPtrAdd |
41-
p1.getArgument(1).toString() = assignPtrAdd.getLValue().toString()
47+
globalValueNumber(p1.getArgument(1)) = globalValueNumber(assignPtrAdd.getLValue())
4248
and p1.getBasicBlock().getAFalseSuccessor*() = assignPtrAdd.getBasicBlock()
4349
)
44-
select
45-
"first fetch", p1, "double fetch", p2
50+
51+
select p2, "Double fetch vulnerability. First fetch was $@.", p1, p1.toString()
52+
4653

4754

4855

0 commit comments

Comments
 (0)