Skip to content

Commit 705529c

Browse files
committed
C++: Split StrLenFunction from PureStrFunction (without changes).
1 parent 59cb5f9 commit 705529c

File tree

1 file changed

+58
-3
lines changed
  • cpp/ql/src/semmle/code/cpp/models/implementations

1 file changed

+58
-3
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Pure.qll

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,72 @@ class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunction, SideE
2020
name = "strpbrk" or
2121
name = "strcmp" or
2222
name = "strcspn" or
23-
name = "strlen" or
2423
name = "strncmp" or
25-
name = "strnlen" or
2624
name = "strrchr" or
2725
name = "strspn" or
2826
name = "strtod" or
2927
name = "strtof" or
3028
name = "strtol" or
3129
name = "strtoll" or
3230
name = "strtoq" or
33-
name = "strtoul" or
31+
name = "strtoul"
32+
)
33+
)
34+
}
35+
36+
override predicate hasArrayInput(int bufParam) {
37+
getParameter(bufParam).getUnspecifiedType() instanceof PointerType
38+
}
39+
40+
override predicate hasArrayWithNullTerminator(int bufParam) {
41+
getParameter(bufParam).getUnspecifiedType() instanceof PointerType
42+
}
43+
44+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
45+
exists(ParameterIndex i |
46+
input.isParameter(i) and
47+
exists(getParameter(i))
48+
or
49+
input.isParameterDeref(i) and
50+
getParameter(i).getUnspecifiedType() instanceof PointerType
51+
) and
52+
(
53+
output.isReturnValueDeref() and
54+
getUnspecifiedType() instanceof PointerType
55+
or
56+
output.isReturnValue()
57+
)
58+
}
59+
60+
override predicate parameterNeverEscapes(int i) {
61+
getParameter(i).getUnspecifiedType() instanceof PointerType and
62+
not parameterEscapesOnlyViaReturn(i)
63+
}
64+
65+
override predicate parameterEscapesOnlyViaReturn(int i) {
66+
i = 0 and
67+
getUnspecifiedType() instanceof PointerType
68+
}
69+
70+
override predicate parameterIsAlwaysReturned(int i) { none() }
71+
72+
override predicate hasOnlySpecificReadSideEffects() { any() }
73+
74+
override predicate hasOnlySpecificWriteSideEffects() { any() }
75+
76+
override predicate hasSpecificReadSideEffect(ParameterIndex i, boolean buffer) {
77+
getParameter(i).getUnspecifiedType() instanceof PointerType and
78+
buffer = true
79+
}
80+
}
81+
82+
class StrLenFunction extends AliasFunction, ArrayFunction, TaintFunction, SideEffectFunction {
83+
StrLenFunction() {
84+
exists(string name |
85+
hasGlobalOrStdName(name) and
86+
(
87+
name = "strlen" or
88+
name = "strnlen" or
3489
name = "wcslen"
3590
)
3691
or

0 commit comments

Comments
 (0)