15
15
import cpp
16
16
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
17
17
18
- predicate numberArgument ( Function f , int size ) {
19
- f .hasGlobalOrStdName ( "write" ) and size = 2
18
+ / * * Pridekat allows you to get the number of the argument used for positioning in the buffer by the name of the function. * /
19
+ predicate numberArgument ( Function f , int apos ) {
20
+ f .hasGlobalOrStdName ( "write" ) and apos = 2
20
21
or
21
- f .hasGlobalOrStdName ( "read" ) and size = 2
22
+ f .hasGlobalOrStdName ( "read" ) and apos = 2
22
23
or
23
- f .hasGlobalOrStdName ( "lseek" ) and size = 1
24
+ f .hasGlobalOrStdName ( "lseek" ) and apos = 1
24
25
or
25
- f .hasGlobalOrStdName ( "memmove" ) and size = 2
26
+ f .hasGlobalOrStdName ( "memmove" ) and apos = 2
26
27
or
27
- f .hasGlobalOrStdName ( "memset" ) and size = 2
28
+ f .hasGlobalOrStdName ( "memset" ) and apos = 2
28
29
or
29
- f .hasGlobalOrStdName ( "memcpy" ) and size = 2
30
+ f .hasGlobalOrStdName ( "memcpy" ) and apos = 2
30
31
or
31
- f .hasGlobalOrStdName ( "memcmp" ) and size = 2
32
+ f .hasGlobalOrStdName ( "memcmp" ) and apos = 2
32
33
or
33
- f .hasGlobalOrStdName ( "strncat" ) and size = 2
34
+ f .hasGlobalOrStdName ( "strncat" ) and apos = 2
34
35
or
35
- f .hasGlobalOrStdName ( "strncpy" ) and size = 2
36
+ f .hasGlobalOrStdName ( "strncpy" ) and apos = 2
36
37
or
37
- f .hasGlobalOrStdName ( "strncmp" ) and size = 2
38
+ f .hasGlobalOrStdName ( "strncmp" ) and apos = 2
38
39
or
39
- f .hasGlobalOrStdName ( "snprintf" ) and size = 1
40
+ f .hasGlobalOrStdName ( "snprintf" ) and apos = 1
40
41
or
41
- f .hasGlobalOrStdName ( "strndup" ) and size = 2
42
- or
43
- f .hasGlobalOrStdName ( "read" ) and size = 2
42
+ f .hasGlobalOrStdName ( "strndup" ) and apos = 2
44
43
}
45
44
46
45
class IfCompareWithZero extends IfStmt {
@@ -55,12 +54,11 @@ class IfCompareWithZero extends IfStmt {
55
54
56
55
from FunctionCall fc , IfCompareWithZero ifc , int na
57
56
where
58
- numberArgument ( fc .getTarget ( ) , na ) and
59
- na >= 0 and
57
+ numberArgument ( fc .getTarget ( ) , na )
60
58
globalValueNumber ( fc .getArgument ( na ) ) = globalValueNumber ( ifc .noZerroOperand ( ) ) and
61
59
dominates ( fc , ifc ) and
62
60
not exists ( IfStmt ifc1 |
63
61
dominates ( ifc1 , fc ) and
64
62
globalValueNumber ( fc .getArgument ( na ) ) = globalValueNumber ( ifc1 .getCondition ( ) .getAChild * ( ) )
65
63
)
66
- select fc , "Argument '$@' will be checked later ." , fc .getArgument ( na ) , fc .getArgument ( na ) .toString ( )
64
+ select fc , "The value of argument '$@' appears to be checked after the call, rather than before it ." , fc .getArgument ( na ) , fc .getArgument ( na ) .toString ( )
0 commit comments