Skip to content

Commit c61a9c5

Browse files
committed
C++: Also taint the return value dereference in the strcat model
1 parent e00585c commit c61a9c5

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ class StrcatFunction extends TaintFunction, DataFlowFunction, ArrayFunction, Sid
5050
}
5151

5252
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
53-
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
54-
input.isParameter(2) and
55-
output.isParameterDeref(0)
56-
or
57-
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and
58-
input.isParameter(3) and
59-
output.isParameterDeref(0)
60-
or
61-
input.isParameterDeref(0) and
62-
output.isParameterDeref(0)
63-
or
64-
input.isParameterDeref(1) and
65-
output.isParameterDeref(0)
53+
(
54+
this.getName() = ["strncat", "wcsncat", "_mbsncat", "_mbsncat_l"] and
55+
input.isParameter(2)
56+
or
57+
this.getName() = ["_mbsncat_l", "_mbsnbcat_l"] and
58+
input.isParameter(3)
59+
or
60+
input.isParameterDeref(0)
61+
or
62+
input.isParameterDeref(1)
63+
) and
64+
(output.isParameterDeref(0) or output.isReturnValueDeref())
6665
}
6766

6867
override predicate hasArrayInput(int param) {

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5964,6 +5964,7 @@
59645964
| taint.cpp:172:10:172:15 | buffer | taint.cpp:172:3:172:8 | call to strcat | |
59655965
| taint.cpp:172:10:172:15 | buffer | taint.cpp:172:10:172:15 | ref arg buffer | TAINT |
59665966
| taint.cpp:172:10:172:15 | ref arg buffer | taint.cpp:173:8:173:13 | buffer | |
5967+
| taint.cpp:172:18:172:24 | tainted | taint.cpp:172:3:172:8 | call to strcat | TAINT |
59675968
| taint.cpp:172:18:172:24 | tainted | taint.cpp:172:10:172:15 | ref arg buffer | TAINT |
59685969
| taint.cpp:180:19:180:19 | p | taint.cpp:180:19:180:19 | p | |
59695970
| taint.cpp:180:19:180:19 | p | taint.cpp:181:9:181:9 | p | |
@@ -6373,12 +6374,14 @@
63736374
| taint.cpp:561:9:561:13 | dest1 | taint.cpp:561:9:561:13 | ref arg dest1 | TAINT |
63746375
| taint.cpp:561:9:561:13 | ref arg dest1 | taint.cpp:560:24:560:28 | dest1 | |
63756376
| taint.cpp:561:9:561:13 | ref arg dest1 | taint.cpp:562:7:562:11 | dest1 | |
6377+
| taint.cpp:561:16:561:21 | source | taint.cpp:561:2:561:7 | call to strcat | TAINT |
63766378
| taint.cpp:561:16:561:21 | source | taint.cpp:561:9:561:13 | ref arg dest1 | TAINT |
63776379
| taint.cpp:562:7:562:11 | ref arg dest1 | taint.cpp:560:24:560:28 | dest1 | |
63786380
| taint.cpp:564:9:564:13 | dest2 | taint.cpp:564:2:564:7 | call to strcat | |
63796381
| taint.cpp:564:9:564:13 | dest2 | taint.cpp:564:9:564:13 | ref arg dest2 | TAINT |
63806382
| taint.cpp:564:9:564:13 | ref arg dest2 | taint.cpp:560:37:560:41 | dest2 | |
63816383
| taint.cpp:564:9:564:13 | ref arg dest2 | taint.cpp:565:7:565:11 | dest2 | |
6384+
| taint.cpp:564:16:564:20 | clean | taint.cpp:564:2:564:7 | call to strcat | TAINT |
63826385
| taint.cpp:564:16:564:20 | clean | taint.cpp:564:9:564:13 | ref arg dest2 | TAINT |
63836386
| taint.cpp:565:7:565:11 | ref arg dest2 | taint.cpp:560:37:560:41 | dest2 | |
63846387
| taint.cpp:572:37:572:41 | dest1 | taint.cpp:572:37:572:41 | dest1 | |
@@ -6405,9 +6408,12 @@
64056408
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:572:37:572:41 | dest1 | |
64066409
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:575:7:575:11 | dest1 | |
64076410
| taint.cpp:574:36:574:40 | ref arg dest1 | taint.cpp:576:8:576:12 | dest1 | |
6411+
| taint.cpp:574:43:574:45 | ptr | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64086412
| taint.cpp:574:43:574:45 | ptr | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
6413+
| taint.cpp:574:48:574:48 | n | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64096414
| taint.cpp:574:48:574:48 | n | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
64106415
| taint.cpp:574:51:574:56 | ref arg source | taint.cpp:573:49:573:54 | source | |
6416+
| taint.cpp:574:51:574:56 | source | taint.cpp:574:25:574:34 | call to _mbsncat_l | TAINT |
64116417
| taint.cpp:574:51:574:56 | source | taint.cpp:574:36:574:40 | ref arg dest1 | TAINT |
64126418
| taint.cpp:575:7:575:11 | ref arg dest1 | taint.cpp:572:37:572:41 | dest1 | |
64136419
| taint.cpp:575:7:575:11 | ref arg dest1 | taint.cpp:576:8:576:12 | dest1 | |
@@ -6421,8 +6427,11 @@
64216427
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:572:85:572:89 | dest3 | |
64226428
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:581:7:581:11 | dest3 | |
64236429
| taint.cpp:580:36:580:40 | ref arg dest3 | taint.cpp:582:8:582:12 | dest3 | |
6430+
| taint.cpp:580:43:580:45 | ptr | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64246431
| taint.cpp:580:43:580:45 | ptr | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
6432+
| taint.cpp:580:48:580:48 | n | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64256433
| taint.cpp:580:48:580:48 | n | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
6434+
| taint.cpp:580:51:580:55 | clean | taint.cpp:580:25:580:34 | call to _mbsncat_l | TAINT |
64266435
| taint.cpp:580:51:580:55 | clean | taint.cpp:580:36:580:40 | ref arg dest3 | TAINT |
64276436
| taint.cpp:580:51:580:55 | ref arg clean | taint.cpp:573:32:573:36 | clean | |
64286437
| taint.cpp:581:7:581:11 | ref arg dest3 | taint.cpp:572:85:572:89 | dest3 | |

cpp/ql/test/library-tests/dataflow/taint-tests/taint.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ void test__mbsncat_l(unsigned char* dest1, unsigned const char* ptr, unsigned ch
574574
unsigned char* dest2 = _mbsncat_l(dest1, ptr, n, source);
575575
sink(dest1); // $ SPURIOUS: ast,ir
576576
sink(*dest1); // $ ast,ir
577-
sink(dest2); // $ SPURIOUS: ir
578-
sink(*dest2); // $ ir
577+
sink(dest2); // $ SPURIOUS: ast,ir
578+
sink(*dest2); // $ ast,ir
579579

580580
unsigned char* dest4 = _mbsncat_l(dest3, ptr, n, clean);
581581
sink(dest3);

0 commit comments

Comments
 (0)