Skip to content

Commit eb7bd6e

Browse files
committed
C++: Flow through putback.
1 parent 7cc60a3 commit eb7bd6e

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,13 @@ class StdBasicOStream extends TemplateClass {
409409

410410
/**
411411
* The `std::ostream` functions `operator<<` (defined as a member function),
412-
* `put` and `write`.
412+
* `put` and `write` and `std::istream::putback`.
413413
*/
414414
class StdOStreamOut extends DataFlowFunction, TaintFunction {
415-
StdOStreamOut() { this.hasQualifiedName("std", "basic_ostream", ["operator<<", "put", "write"]) }
415+
StdOStreamOut() {
416+
this.hasQualifiedName("std", "basic_ostream", ["operator<<", "put", "write"]) or
417+
this.hasQualifiedName("std", "basic_istream", "putback")
418+
}
416419

417420
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
418421
// flow from qualifier to return value

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,10 +1881,16 @@
18811881
| stringstream.cpp:194:7:194:8 | ref arg ss | stringstream.cpp:195:7:195:8 | ss | |
18821882
| stringstream.cpp:194:7:194:8 | ref arg ss | stringstream.cpp:196:7:196:8 | ss | |
18831883
| stringstream.cpp:194:7:194:8 | ref arg ss | stringstream.cpp:197:7:197:8 | ss | |
1884+
| stringstream.cpp:194:7:194:8 | ss | stringstream.cpp:194:10:194:16 | call to putback | |
1885+
| stringstream.cpp:194:18:194:20 | 98 | stringstream.cpp:194:7:194:8 | ref arg ss | TAINT |
1886+
| stringstream.cpp:194:18:194:20 | 98 | stringstream.cpp:194:10:194:16 | call to putback | TAINT |
18841887
| stringstream.cpp:195:7:195:8 | ref arg ss | stringstream.cpp:196:7:196:8 | ss | |
18851888
| stringstream.cpp:195:7:195:8 | ref arg ss | stringstream.cpp:197:7:197:8 | ss | |
18861889
| stringstream.cpp:195:7:195:8 | ss | stringstream.cpp:195:10:195:12 | call to get | TAINT |
18871890
| stringstream.cpp:196:7:196:8 | ref arg ss | stringstream.cpp:197:7:197:8 | ss | |
1891+
| stringstream.cpp:196:7:196:8 | ss | stringstream.cpp:196:10:196:16 | call to putback | |
1892+
| stringstream.cpp:196:18:196:32 | call to source | stringstream.cpp:196:7:196:8 | ref arg ss | TAINT |
1893+
| stringstream.cpp:196:18:196:32 | call to source | stringstream.cpp:196:10:196:16 | call to putback | TAINT |
18881894
| stringstream.cpp:197:7:197:8 | ss | stringstream.cpp:197:10:197:12 | call to get | TAINT |
18891895
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |
18901896
| structlikeclass.cpp:5:7:5:7 | Unknown literal | structlikeclass.cpp:5:7:5:7 | constructor init of field v | TAINT |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,6 @@ void test_stringstream_putback()
193193
sink(ss.get());
194194
sink(ss.putback('b'));
195195
sink(ss.get());
196-
sink(ss.putback(ns_char::source())); // tainted [NOT DETECTED]
197-
sink(ss.get()); // tainted [NOT DETECTED]
196+
sink(ss.putback(ns_char::source())); // tainted
197+
sink(ss.get()); // tainted
198198
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@
220220
| stringstream.cpp:181:7:181:8 | c2 | stringstream.cpp:143:14:143:19 | call to source |
221221
| stringstream.cpp:183:7:183:8 | c4 | stringstream.cpp:143:14:143:19 | call to source |
222222
| stringstream.cpp:185:7:185:8 | c6 | stringstream.cpp:143:14:143:19 | call to source |
223+
| stringstream.cpp:196:10:196:16 | call to putback | stringstream.cpp:196:18:196:32 | call to source |
224+
| stringstream.cpp:197:10:197:12 | call to get | stringstream.cpp:196:18:196:32 | call to source |
223225
| structlikeclass.cpp:35:8:35:9 | s1 | structlikeclass.cpp:29:22:29:27 | call to source |
224226
| structlikeclass.cpp:36:8:36:9 | s2 | structlikeclass.cpp:30:24:30:29 | call to source |
225227
| 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@
222222
| stringstream.cpp:181:7:181:8 | stringstream.cpp:143:14:143:19 | AST only |
223223
| stringstream.cpp:183:7:183:8 | stringstream.cpp:143:14:143:19 | AST only |
224224
| stringstream.cpp:185:7:185:8 | stringstream.cpp:143:14:143:19 | AST only |
225+
| stringstream.cpp:196:10:196:16 | stringstream.cpp:196:18:196:32 | AST only |
226+
| stringstream.cpp:197:10:197:12 | stringstream.cpp:196:18:196:32 | AST only |
225227
| swap1.cpp:78:12:78:16 | swap1.cpp:69:23:69:23 | AST only |
226228
| swap1.cpp:87:13:87:17 | swap1.cpp:82:16:82:21 | AST only |
227229
| swap1.cpp:88:13:88:17 | swap1.cpp:81:27:81:28 | AST only |

0 commit comments

Comments
 (0)