Skip to content

Commit 7349333

Browse files
committed
C++: Taint through char append.
1 parent 3c0e7a7 commit 7349333

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ class StdStringAppend extends TaintFunction {
4949
}
5050

5151
/**
52-
* Gets the index of a parameter to this function that is a string.
52+
* Gets the index of a parameter to this function that is a string (or
53+
* character).
5354
*/
5455
int getAStringParameter() {
5556
getParameter(result).getType() instanceof PointerType or
56-
getParameter(result).getType() instanceof ReferenceType
57+
getParameter(result).getType() instanceof ReferenceType or
58+
getParameter(result).getType() = getDeclaringType().getTemplateArgument(0) // i.e. `std::basic_string::CharT`
5759
}
5860

5961
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@
579579
| stl.cpp:366:3:366:4 | ref arg s9 | stl.cpp:367:8:367:9 | s9 | |
580580
| stl.cpp:366:13:366:15 | | stl.cpp:366:3:366:4 | ref arg s9 | TAINT |
581581
| stl.cpp:366:13:366:15 | | stl.cpp:366:6:366:11 | call to append | TAINT |
582+
| stl.cpp:371:19:371:23 | abc | stl.cpp:371:19:371:24 | call to basic_string | TAINT |
583+
| stl.cpp:371:19:371:24 | call to basic_string | stl.cpp:374:3:374:5 | s10 | |
584+
| stl.cpp:371:19:371:24 | call to basic_string | stl.cpp:375:8:375:10 | s10 | |
585+
| stl.cpp:372:12:372:26 | call to source | stl.cpp:374:17:374:17 | c | |
586+
| stl.cpp:374:3:374:5 | ref arg s10 | stl.cpp:375:8:375:10 | s10 | |
587+
| stl.cpp:374:17:374:17 | c | stl.cpp:374:3:374:5 | ref arg s10 | TAINT |
588+
| stl.cpp:374:17:374:17 | c | stl.cpp:374:7:374:12 | call to append | TAINT |
582589
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |
583590
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |
584591
| structlikeclass.cpp:5:7:5:7 | this | structlikeclass.cpp:5:7:5:7 | constructor init of field v [pre-this] | |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,6 @@ void test_string_append() {
372372
char c = ns_char::source();
373373

374374
s10.append(1, c);
375-
sink(s10); // tainted [NOT DETECTED]
375+
sink(s10); // tainted
376376
}
377377
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
| stl.cpp:358:8:358:9 | s7 | stl.cpp:356:9:356:14 | call to source |
6363
| stl.cpp:362:8:362:9 | s8 | stl.cpp:345:18:345:23 | call to source |
6464
| stl.cpp:367:8:367:9 | s9 | stl.cpp:365:13:365:18 | call to source |
65+
| stl.cpp:375:8:375:10 | s10 | stl.cpp:372:12:372:26 | call to source |
6566
| structlikeclass.cpp:35:8:35:9 | s1 | structlikeclass.cpp:29:22:29:27 | call to source |
6667
| structlikeclass.cpp:36:8:36:9 | s2 | structlikeclass.cpp:30:24:30:29 | call to source |
6768
| structlikeclass.cpp:37:8:37:9 | s3 | structlikeclass.cpp:29:22:29:27 | call to source |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
| stl.cpp:358:8:358:9 | stl.cpp:356:9:356:14 | AST only |
6060
| stl.cpp:362:8:362:9 | stl.cpp:345:18:345:23 | AST only |
6161
| stl.cpp:367:8:367:9 | stl.cpp:365:13:365:18 | AST only |
62+
| stl.cpp:375:8:375:10 | stl.cpp:372:12:372:26 | AST only |
6263
| structlikeclass.cpp:35:8:35:9 | structlikeclass.cpp:29:22:29:27 | AST only |
6364
| structlikeclass.cpp:36:8:36:9 | structlikeclass.cpp:30:24:30:29 | AST only |
6465
| structlikeclass.cpp:37:8:37:9 | structlikeclass.cpp:29:22:29:27 | AST only |

0 commit comments

Comments
 (0)