18
18
import cpp
19
19
import Buffer
20
20
private import semmle.code.cpp.valuenumbering.GlobalValueNumbering
21
+ private import semmle.code.cpp.models.implementations.Strcpy
21
22
22
23
predicate isSizePlus ( Expr e , BufferSizeExpr baseSize , int plus ) {
23
24
// baseSize
@@ -41,33 +42,6 @@ predicate isSizePlus(Expr e, BufferSizeExpr baseSize, int plus) {
41
42
)
42
43
}
43
44
44
- predicate strncpyFunction ( Function f , int argDest , int argSrc , int argLimit ) {
45
- exists ( string name | name = f .getName ( ) |
46
- name =
47
- [
48
- "strcpy_s" , // strcpy_s(dst, max_amount, src)
49
- "wcscpy_s" , // wcscpy_s(dst, max_amount, src)
50
- "_mbscpy_s" // _mbscpy_s(dst, max_amount, src)
51
- ] and
52
- argDest = 0 and
53
- argSrc = 2 and
54
- argLimit = 1
55
- or
56
- name =
57
- [
58
- "strncpy" , // strncpy(dst, src, max_amount)
59
- "strncpy_l" , // strncpy_l(dst, src, max_amount, locale)
60
- "wcsncpy" , // wcsncpy(dst, src, max_amount)
61
- "_wcsncpy_l" , // _wcsncpy_l(dst, src, max_amount, locale)
62
- "_mbsncpy" , // _mbsncpy(dst, src, max_amount)
63
- "_mbsncpy_l" // _mbsncpy_l(dst, src, max_amount, locale)
64
- ] and
65
- argDest = 0 and
66
- argSrc = 1 and
67
- argLimit = 2
68
- )
69
- }
70
-
71
45
string nthString ( int num ) {
72
46
num = 0 and
73
47
result = "first"
@@ -96,11 +70,13 @@ int arrayExprFixedSize(Expr e) {
96
70
}
97
71
98
72
from
99
- Function f , FunctionCall fc , int argDest , int argSrc , int argLimit , int charSize , Access copyDest ,
73
+ StrcpyFunction f , FunctionCall fc , int argDest , int argSrc , int argLimit , int charSize , Access copyDest ,
100
74
Access copySource , string name , string nth
101
75
where
102
76
f = fc .getTarget ( ) and
103
- strncpyFunction ( f , argDest , argSrc , argLimit ) and
77
+ argDest = f .getParamDest ( ) and
78
+ argSrc = f .getParamSrc ( ) and
79
+ argLimit = f .getParamSize ( ) and
104
80
copyDest = fc .getArgument ( argDest ) and
105
81
copySource = fc .getArgument ( argSrc ) and
106
82
// Some of the functions operate on a larger char type, like `wchar_t`, so we
0 commit comments