Skip to content

Commit f0da0d9

Browse files
committed
C++: Add a few more models I noticed while here.
1 parent 2b6a75f commit f0da0d9

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

cpp/ql/lib/semmle/code/cpp/models/implementations/Memcpy.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import semmle.code.cpp.models.interfaces.Taint
1212
import semmle.code.cpp.models.interfaces.NonThrowing
1313

1414
/**
15-
* The standard functions `memcpy`, `memmove` and `bcopy`; and the gcc variant
16-
* `__builtin___memcpy_chk`.
15+
* The standard functions `memcpy`, `memmove` and `bcopy`; and variants such as
16+
* `__builtin___memcpy_chk` and `__builtin___memmove_chk`.
1717
*/
1818
private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffectFunction,
1919
AliasFunction, NonCppThrowingFunction
@@ -27,7 +27,9 @@ private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffect
2727
// bcopy(src, dest, num)
2828
// mempcpy(dest, src, num)
2929
// memccpy(dest, src, c, n)
30-
this.hasGlobalName(["bcopy", mempcpy(), "memccpy", "__builtin___memcpy_chk"])
30+
this.hasGlobalName([
31+
"bcopy", mempcpy(), "memccpy", "__builtin___memcpy_chk", "__builtin___memmove_chk"
32+
])
3133
}
3234

3335
/**

cpp/ql/lib/semmle/code/cpp/models/implementations/Memset.qll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, Alias
1919
this.hasGlobalOrStdName("wmemset")
2020
or
2121
this.hasGlobalName([
22-
bzero(), "__builtin_memset", "__builtin_memset_chk", "RtlZeroMemory", "RtlSecureZeroMemory"
22+
bzero(), "__builtin_memset", "__builtin_memset_chk", "__builtin___memset_chk",
23+
"RtlZeroMemory", "RtlSecureZeroMemory"
2324
])
2425
}
2526

@@ -32,7 +33,7 @@ private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, Alias
3233
or
3334
this.hasGlobalOrStdName("wmemset")
3435
or
35-
this.hasGlobalName(["__builtin_memset", "__builtin_memset_chk"])
36+
this.hasGlobalName(["__builtin_memset", "__builtin_memset_chk", "__builtin___memset_chk"])
3637
) and
3738
result = 1
3839
}

cpp/ql/lib/semmle/code/cpp/models/implementations/Strcat.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
3030
"_mbsncat", // _mbsncat(dst, src, max_amount)
3131
"_mbsncat_l", // _mbsncat_l(dst, src, max_amount, locale)
3232
"_mbsnbcat", // _mbsnbcat(dest, src, count)
33-
"_mbsnbcat_l" // _mbsnbcat_l(dest, src, count, locale)
33+
"_mbsnbcat_l", // _mbsnbcat_l(dest, src, count, locale)
34+
"__builtin___strcat_chk", // __builtin___strcat_chk (dest, src, magic);
35+
"__builtin___strncat_chk" // __builtin___strncat_chk (dest, src, max_amount, magic);
3436
])
3537
}
3638

@@ -56,7 +58,11 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
5658

5759
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
5860
(
59-
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
61+
this.getName() =
62+
[
63+
"strncat", "wcsncat", "_mbsncat", "_mbsncat_l", "__builtin___strncat_chk",
64+
"__builtin___strcat_chk"
65+
] and
6066
input.isParameter(2)
6167
or
6268
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and

cpp/ql/lib/semmle/code/cpp/models/implementations/Strcpy.qll

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
3636
"_mbsnbcpy", // _mbsnbcpy(dest, src, max_amount)
3737
"stpcpy", // stpcpy(dest, src)
3838
"stpncpy", // stpncpy(dest, src, max_amount)
39-
"strlcpy" // strlcpy(dst, src, dst_size)
39+
"strlcpy", // strlcpy(dst, src, dst_size)
40+
"__builtin___strcpy_chk", // __builtin___strcpy_chk (dest, src, magic);
41+
"__builtin___stpcpy_chk", // __builtin___stpcpy_chk (dest, src, magic);
42+
"__builtin___stpncpy_chk", // __builtin___stpncpy_chk(dest, src, max_amount, magic)
43+
"__builtin___strncpy_chk" // __builtin___strncpy_chk (dest, src, max_amount, magic);
4044
])
4145
or
4246
(
@@ -69,7 +73,11 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
6973
if this.isSVariant()
7074
then result = 1
7175
else (
72-
this.getName().matches(["%ncpy%", "%nbcpy%", "%xfrm%", "strlcpy"]) and
76+
this.getName()
77+
.matches([
78+
"%ncpy%", "%nbcpy%", "%xfrm%", "strlcpy", "__builtin___strcpy_chk",
79+
"__builtin___stpcpy_chk", "__builtin___stpncpy_chk", "__builtin___strncpy_chk"
80+
]) and
7381
result = 2
7482
)
7583
}

0 commit comments

Comments
 (0)