Skip to content

Commit 05385eb

Browse files
authored
Merge pull request github#14587 from MathiasVP/fix-indirect-strtok-model
C++: Fix `strtok` model for indirections
2 parents 27646ce + 032572b commit 05385eb

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private class Strtok extends ArrayFunction, AliasFunction, TaintFunction, SideEf
3232

3333
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
3434
input.isParameter(0) and output.isReturnValue()
35+
or
36+
input.isParameterDeref(0) and output.isReturnValueDeref()
3537
}
3638

3739
override predicate hasOnlySpecificReadSideEffects() { none() }

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6622,6 +6622,13 @@ WARNING: Module TaintTracking has been deprecated and may be removed in future (
66226622
| taint.cpp:711:13:711:13 | s | taint.cpp:711:2:711:8 | call to strncpy | TAINT |
66236623
| taint.cpp:711:13:711:13 | s | taint.cpp:711:10:711:10 | ref arg d | TAINT |
66246624
| taint.cpp:712:7:712:7 | ref arg d | taint.cpp:709:25:709:25 | d | |
6625+
| taint.cpp:718:17:718:31 | call to indirect_source | taint.cpp:720:27:720:32 | source | |
6626+
| taint.cpp:719:22:719:29 | ,.-;:_ | taint.cpp:720:35:720:39 | delim | |
6627+
| taint.cpp:719:22:719:29 | ,.-;:_ | taint.cpp:722:8:722:12 | delim | |
6628+
| taint.cpp:720:20:720:25 | call to strtok | taint.cpp:721:8:721:16 | tokenized | |
6629+
| taint.cpp:720:27:720:32 | source | taint.cpp:720:20:720:25 | call to strtok | TAINT |
6630+
| taint.cpp:721:8:721:16 | tokenized | taint.cpp:721:7:721:16 | * ... | TAINT |
6631+
| taint.cpp:722:8:722:12 | delim | taint.cpp:722:7:722:12 | * ... | TAINT |
66256632
| vector.cpp:16:43:16:49 | source1 | vector.cpp:17:26:17:32 | source1 | |
66266633
| vector.cpp:16:43:16:49 | source1 | vector.cpp:31:38:31:44 | source1 | |
66276634
| vector.cpp:17:21:17:33 | call to vector | vector.cpp:19:14:19:14 | v | |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,4 +710,14 @@ void test_strncpy(char* d, char* s) {
710710
argument_source(s);
711711
strncpy(d, s, 16);
712712
sink(d); // $ ast ir
713+
}
714+
715+
char* indirect_source();
716+
717+
void test_strtok_indirect() {
718+
char *source = indirect_source();
719+
const char* delim = ",.-;:_";
720+
char* tokenized = strtok(source, delim);
721+
sink(*tokenized); // $ ir MISSING: ast
722+
sink(*delim);
713723
}

0 commit comments

Comments
 (0)