Skip to content

Commit 0b91310

Browse files
committed
C++: Add models for strlcpy and strlcat
1 parent 4ae35d1 commit 0b91310

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
2525
"_mbsncat", // _mbsncat(dst, src, max_amount)
2626
"_mbsncat_l", // _mbsncat_l(dst, src, max_amount, locale)
2727
"_mbsnbcat", // _mbsnbcat(dest, src, count)
28-
"_mbsnbcat_l" // _mbsnbcat_l(dest, src, count, locale)
28+
"_mbsnbcat_l", // _mbsnbcat_l(dest, src, count, locale)
29+
"strlcat" // strncat(dst, src, dst_size)
2930
])
3031
}
3132

@@ -51,7 +52,7 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
5152

5253
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
5354
(
54-
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
55+
this.getName() = ["strncat", "strlcat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
5556
input.isParameter(2)
5657
or
5758
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
3232
"wcsxfrm_l", // _strxfrm_l(dest, src, max_amount, locale)
3333
"_mbsnbcpy", // _mbsnbcpy(dest, src, max_amount)
3434
"stpcpy", // stpcpy(dest, src)
35-
"stpncpy" // stpcpy(dest, src, max_amount)
35+
"stpncpy", // stpcpy(dest, src, max_amount)
36+
"strlcpy" // strlcpy(dst, src, dst_size)
3637
])
3738
or
3839
(
@@ -60,7 +61,7 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction, Sid
6061
if this.isSVariant()
6162
then result = 1
6263
else (
63-
this.getName().matches(["%ncpy%", "%nbcpy%", "%xfrm%"]) and
64+
this.getName().matches(["%ncpy%", "%nbcpy%", "%xfrm%", "%lcpy%"]) and
6465
result = 2
6566
)
6667
}

0 commit comments

Comments
 (0)