Skip to content

Commit 4326699

Browse files
committed
CPP: Extend the StrcpyFunction model.
1 parent 39be9c3 commit 4326699

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction {
1212
this.hasName("_mbscpy") or
1313
this.hasName("wcscpy") or
1414
this.hasName("strncpy") or
15+
this.hasName("_strncpy_l") or
1516
this.hasName("_mbsncpy") or
16-
this.hasName("wcsncpy")
17+
this.hasName("_mbsncpy_l") or
18+
this.hasName("wcsncpy") or
19+
this.hasName("_wcsncpy_l")
1720
}
1821

1922
override predicate hasArrayInput(int bufParam) {
@@ -31,8 +34,11 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction {
3134
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
3235
(
3336
this.hasName("strncpy") or
37+
this.hasName("_strncpy_l") or
3438
this.hasName("_mbsncpy") or
35-
this.hasName("wcsncpy")
39+
this.hasName("_mbsncpy_l") or
40+
this.hasName("wcsncpy") or
41+
this.hasName("_wcsncpy_l")
3642
) and
3743
bufParam = 0 and
3844
countParam = 2
@@ -76,8 +82,11 @@ class StrcpyFunction extends ArrayFunction, DataFlowFunction, TaintFunction {
7682
// these may do only a partial copy of the input buffer to the output
7783
// buffer
7884
this.hasName("strncpy") or
85+
this.hasName("_strncpy_l") or
7986
this.hasName("_mbsncpy") or
80-
this.hasName("wcsncpy")
87+
this.hasName("_mbsncpy_l") or
88+
this.hasName("wcsncpy") or
89+
this.hasName("_wcsncpy_l")
8190
) and (
8291
input.isInParameter(2) or
8392
input.isInParameterPointer(1)

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/UsingStrcpyAsBoolean/UsingStrcpyAsBoolean.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
| test.cpp:103:9:103:15 | call to strncpy | Return value of strncpy used directly in a conditional expression. |
2020
| test.cpp:107:9:107:15 | call to wcsncpy | Return value of wcsncpy used directly in a conditional expression. |
2121
| test.cpp:111:9:111:16 | call to _mbsncpy | Return value of _mbsncpy used directly in a conditional expression. |
22+
| test.cpp:115:9:115:18 | call to _strncpy_l | Return value of _strncpy_l used directly in a conditional expression. |
23+
| test.cpp:119:9:119:18 | call to _wcsncpy_l | Return value of _wcsncpy_l used directly in a conditional expression. |
24+
| test.cpp:123:9:123:18 | call to _mbsncpy_l | Return value of _mbsncpy_l used directly in a conditional expression. |
2225
| test.cpp:127:9:127:37 | ! ... | Return value of strncpy used in a logical operation. |
2326
| test.cpp:131:14:131:20 | call to strncpy | Return value of strncpy used as a Boolean. |
2427
| test.cpp:133:19:133:47 | ! ... | Return value of strncpy used in a logical operation. |

0 commit comments

Comments
 (0)