Skip to content

Commit 0234bca

Browse files
committed
C++: Fix a hole in StdStringAppend and clarify comments.
1 parent a11ca06 commit 0234bca

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ class StdStringAppend extends TaintFunction {
6666
}
6767

6868
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
69-
// flow from parameter to string itself (qualifier) and return value
70-
input.isParameterDeref(getAStringParameter()) and
69+
// flow from string and parameter to string (qualifier) and return value
70+
(
71+
input.isQualifierObject() or
72+
input.isParameterDeref(getAStringParameter())
73+
) and
7174
(
7275
output.isQualifierObject() or
7376
output.isReturnValueDeref()
@@ -140,6 +143,7 @@ class StdStringSwap extends TaintFunction {
140143
StdStringSwap() { this.hasQualifiedName("std", "basic_string", "swap") }
141144

142145
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
146+
// str1.swap(str2)
143147
input.isQualifierObject() and
144148
output.isParameterDeref(0)
145149
or

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@
457457
| string.cpp:160:8:160:9 | s3 | string.cpp:161:3:161:4 | s6 | |
458458
| string.cpp:160:8:160:9 | s3 | string.cpp:162:8:162:9 | s6 | |
459459
| string.cpp:161:3:161:4 | ref arg s6 | string.cpp:162:8:162:9 | s6 | |
460+
| string.cpp:161:3:161:4 | s6 | string.cpp:161:6:161:6 | call to operator+= | TAINT |
460461
| string.cpp:161:9:161:10 | s4 | string.cpp:161:3:161:4 | ref arg s6 | TAINT |
461462
| string.cpp:161:9:161:10 | s4 | string.cpp:161:6:161:6 | call to operator+= | TAINT |
462463
| string.cpp:164:8:164:9 | s3 | string.cpp:164:3:164:9 | ... = ... | |
@@ -465,15 +466,18 @@
465466
| string.cpp:164:8:164:9 | s3 | string.cpp:167:8:167:9 | s7 | |
466467
| string.cpp:165:3:165:4 | ref arg s7 | string.cpp:166:3:166:4 | s7 | |
467468
| string.cpp:165:3:165:4 | ref arg s7 | string.cpp:167:8:167:9 | s7 | |
469+
| string.cpp:165:3:165:4 | s7 | string.cpp:165:6:165:6 | call to operator+= | TAINT |
468470
| string.cpp:165:9:165:14 | call to source | string.cpp:165:3:165:4 | ref arg s7 | TAINT |
469471
| string.cpp:165:9:165:14 | call to source | string.cpp:165:6:165:6 | call to operator+= | TAINT |
470472
| string.cpp:166:3:166:4 | ref arg s7 | string.cpp:167:8:167:9 | s7 | |
473+
| string.cpp:166:3:166:4 | s7 | string.cpp:166:6:166:6 | call to operator+= | TAINT |
471474
| string.cpp:166:9:166:11 | | string.cpp:166:3:166:4 | ref arg s7 | TAINT |
472475
| string.cpp:166:9:166:11 | | string.cpp:166:6:166:6 | call to operator+= | TAINT |
473476
| string.cpp:169:8:169:9 | s3 | string.cpp:169:3:169:9 | ... = ... | |
474477
| string.cpp:169:8:169:9 | s3 | string.cpp:170:3:170:4 | s8 | |
475478
| string.cpp:169:8:169:9 | s3 | string.cpp:171:8:171:9 | s8 | |
476479
| string.cpp:170:3:170:4 | ref arg s8 | string.cpp:171:8:171:9 | s8 | |
480+
| string.cpp:170:3:170:4 | s8 | string.cpp:170:6:170:11 | call to append | TAINT |
477481
| string.cpp:170:13:170:14 | s4 | string.cpp:170:3:170:4 | ref arg s8 | TAINT |
478482
| string.cpp:170:13:170:14 | s4 | string.cpp:170:6:170:11 | call to append | TAINT |
479483
| string.cpp:173:8:173:9 | s3 | string.cpp:173:3:173:9 | ... = ... | |
@@ -482,16 +486,19 @@
482486
| string.cpp:173:8:173:9 | s3 | string.cpp:176:8:176:9 | s9 | |
483487
| string.cpp:174:3:174:4 | ref arg s9 | string.cpp:175:3:175:4 | s9 | |
484488
| string.cpp:174:3:174:4 | ref arg s9 | string.cpp:176:8:176:9 | s9 | |
489+
| string.cpp:174:3:174:4 | s9 | string.cpp:174:6:174:11 | call to append | TAINT |
485490
| string.cpp:174:13:174:18 | call to source | string.cpp:174:3:174:4 | ref arg s9 | TAINT |
486491
| string.cpp:174:13:174:18 | call to source | string.cpp:174:6:174:11 | call to append | TAINT |
487492
| string.cpp:175:3:175:4 | ref arg s9 | string.cpp:176:8:176:9 | s9 | |
493+
| string.cpp:175:3:175:4 | s9 | string.cpp:175:6:175:11 | call to append | TAINT |
488494
| string.cpp:175:13:175:15 | | string.cpp:175:3:175:4 | ref arg s9 | TAINT |
489495
| string.cpp:175:13:175:15 | | string.cpp:175:6:175:11 | call to append | TAINT |
490496
| string.cpp:180:19:180:23 | abc | string.cpp:180:19:180:24 | call to basic_string | TAINT |
491497
| string.cpp:180:19:180:24 | call to basic_string | string.cpp:183:3:183:5 | s10 | |
492498
| string.cpp:180:19:180:24 | call to basic_string | string.cpp:184:8:184:10 | s10 | |
493499
| string.cpp:181:12:181:26 | call to source | string.cpp:183:17:183:17 | c | |
494500
| string.cpp:183:3:183:5 | ref arg s10 | string.cpp:184:8:184:10 | s10 | |
501+
| string.cpp:183:3:183:5 | s10 | string.cpp:183:7:183:12 | call to append | TAINT |
495502
| string.cpp:183:17:183:17 | c | string.cpp:183:3:183:5 | ref arg s10 | TAINT |
496503
| string.cpp:183:17:183:17 | c | string.cpp:183:7:183:12 | call to append | TAINT |
497504
| string.cpp:189:17:189:23 | hello | string.cpp:189:17:189:24 | call to basic_string | TAINT |
@@ -535,24 +542,28 @@
535542
| string.cpp:214:7:214:8 | s1 | string.cpp:215:7:215:8 | s3 | |
536543
| string.cpp:214:7:214:8 | s1 | string.cpp:216:7:216:8 | s3 | |
537544
| string.cpp:215:7:215:8 | ref arg s3 | string.cpp:216:7:216:8 | s3 | |
545+
| string.cpp:215:7:215:8 | s3 | string.cpp:215:10:215:15 | call to insert | TAINT |
538546
| string.cpp:215:20:215:21 | s1 | string.cpp:215:7:215:8 | ref arg s3 | TAINT |
539547
| string.cpp:215:20:215:21 | s1 | string.cpp:215:10:215:15 | call to insert | TAINT |
540548
| string.cpp:218:7:218:8 | s2 | string.cpp:218:2:218:8 | ... = ... | |
541549
| string.cpp:218:7:218:8 | s2 | string.cpp:219:7:219:8 | s4 | |
542550
| string.cpp:218:7:218:8 | s2 | string.cpp:220:7:220:8 | s4 | |
543551
| string.cpp:219:7:219:8 | ref arg s4 | string.cpp:220:7:220:8 | s4 | |
552+
| string.cpp:219:7:219:8 | s4 | string.cpp:219:10:219:15 | call to insert | TAINT |
544553
| string.cpp:219:20:219:21 | s1 | string.cpp:219:7:219:8 | ref arg s4 | TAINT |
545554
| string.cpp:219:20:219:21 | s1 | string.cpp:219:10:219:15 | call to insert | TAINT |
546555
| string.cpp:222:7:222:8 | s1 | string.cpp:222:2:222:8 | ... = ... | |
547556
| string.cpp:222:7:222:8 | s1 | string.cpp:223:7:223:8 | s5 | |
548557
| string.cpp:222:7:222:8 | s1 | string.cpp:224:7:224:8 | s5 | |
549558
| string.cpp:223:7:223:8 | ref arg s5 | string.cpp:224:7:224:8 | s5 | |
559+
| string.cpp:223:7:223:8 | s5 | string.cpp:223:10:223:15 | call to insert | TAINT |
550560
| string.cpp:223:20:223:21 | s2 | string.cpp:223:7:223:8 | ref arg s5 | TAINT |
551561
| string.cpp:223:20:223:21 | s2 | string.cpp:223:10:223:15 | call to insert | TAINT |
552562
| string.cpp:226:7:226:8 | s1 | string.cpp:226:2:226:8 | ... = ... | |
553563
| string.cpp:226:7:226:8 | s1 | string.cpp:227:7:227:8 | s6 | |
554564
| string.cpp:226:7:226:8 | s1 | string.cpp:228:7:228:8 | s6 | |
555565
| string.cpp:227:7:227:8 | ref arg s6 | string.cpp:228:7:228:8 | s6 | |
566+
| string.cpp:227:7:227:8 | s6 | string.cpp:227:10:227:15 | call to insert | TAINT |
556567
| string.cpp:227:24:227:24 | c | string.cpp:227:7:227:8 | ref arg s6 | TAINT |
557568
| string.cpp:227:24:227:24 | c | string.cpp:227:10:227:15 | call to insert | TAINT |
558569
| string.cpp:232:17:232:23 | hello | string.cpp:232:17:232:24 | call to basic_string | TAINT |
@@ -569,24 +580,28 @@
569580
| string.cpp:237:7:237:8 | s1 | string.cpp:238:7:238:8 | s3 | |
570581
| string.cpp:237:7:237:8 | s1 | string.cpp:239:7:239:8 | s3 | |
571582
| string.cpp:238:7:238:8 | ref arg s3 | string.cpp:239:7:239:8 | s3 | |
583+
| string.cpp:238:7:238:8 | s3 | string.cpp:238:10:238:16 | call to replace | TAINT |
572584
| string.cpp:238:24:238:25 | s1 | string.cpp:238:7:238:8 | ref arg s3 | TAINT |
573585
| string.cpp:238:24:238:25 | s1 | string.cpp:238:10:238:16 | call to replace | TAINT |
574586
| string.cpp:241:7:241:8 | s2 | string.cpp:241:2:241:8 | ... = ... | |
575587
| string.cpp:241:7:241:8 | s2 | string.cpp:242:7:242:8 | s4 | |
576588
| string.cpp:241:7:241:8 | s2 | string.cpp:243:7:243:8 | s4 | |
577589
| string.cpp:242:7:242:8 | ref arg s4 | string.cpp:243:7:243:8 | s4 | |
590+
| string.cpp:242:7:242:8 | s4 | string.cpp:242:10:242:16 | call to replace | TAINT |
578591
| string.cpp:242:24:242:25 | s1 | string.cpp:242:7:242:8 | ref arg s4 | TAINT |
579592
| string.cpp:242:24:242:25 | s1 | string.cpp:242:10:242:16 | call to replace | TAINT |
580593
| string.cpp:245:7:245:8 | s1 | string.cpp:245:2:245:8 | ... = ... | |
581594
| string.cpp:245:7:245:8 | s1 | string.cpp:246:7:246:8 | s5 | |
582595
| string.cpp:245:7:245:8 | s1 | string.cpp:247:7:247:8 | s5 | |
583596
| string.cpp:246:7:246:8 | ref arg s5 | string.cpp:247:7:247:8 | s5 | |
597+
| string.cpp:246:7:246:8 | s5 | string.cpp:246:10:246:16 | call to replace | TAINT |
584598
| string.cpp:246:24:246:25 | s2 | string.cpp:246:7:246:8 | ref arg s5 | TAINT |
585599
| string.cpp:246:24:246:25 | s2 | string.cpp:246:10:246:16 | call to replace | TAINT |
586600
| string.cpp:249:7:249:8 | s1 | string.cpp:249:2:249:8 | ... = ... | |
587601
| string.cpp:249:7:249:8 | s1 | string.cpp:250:7:250:8 | s6 | |
588602
| string.cpp:249:7:249:8 | s1 | string.cpp:251:7:251:8 | s6 | |
589603
| string.cpp:250:7:250:8 | ref arg s6 | string.cpp:251:7:251:8 | s6 | |
604+
| string.cpp:250:7:250:8 | s6 | string.cpp:250:10:250:16 | call to replace | TAINT |
590605
| string.cpp:250:28:250:28 | c | string.cpp:250:7:250:8 | ref arg s6 | TAINT |
591606
| string.cpp:250:28:250:28 | c | string.cpp:250:10:250:16 | call to replace | TAINT |
592607
| string.cpp:255:17:255:20 | {...} | string.cpp:260:10:260:11 | b1 | |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void test_string_insert() {
216216
sink(s3);
217217

218218
s4 = s2;
219-
sink(s4.insert(0, s1)); // tainted [NOT DETECTED]
219+
sink(s4.insert(0, s1)); // tainted
220220
sink(s4); // tainted
221221

222222
s5 = s1;
@@ -239,7 +239,7 @@ void test_string_replace() {
239239
sink(s3);
240240

241241
s4 = s2;
242-
sink(s4.replace(1, 2, s1)); // tainted [NOT DETECTED]
242+
sink(s4.replace(1, 2, s1)); // tainted
243243
sink(s4); // tainted
244244

245245
s5 = s1;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@
6565
| string.cpp:201:10:201:15 | call to assign | string.cpp:191:11:191:25 | call to source |
6666
| string.cpp:202:7:202:8 | s5 | string.cpp:191:11:191:25 | call to source |
6767
| string.cpp:205:7:205:8 | s6 | string.cpp:193:17:193:22 | call to source |
68+
| string.cpp:219:10:219:15 | call to insert | string.cpp:210:17:210:22 | call to source |
6869
| string.cpp:220:7:220:8 | s4 | string.cpp:210:17:210:22 | call to source |
6970
| string.cpp:223:10:223:15 | call to insert | string.cpp:210:17:210:22 | call to source |
7071
| string.cpp:224:7:224:8 | s5 | string.cpp:210:17:210:22 | call to source |
7172
| string.cpp:227:10:227:15 | call to insert | string.cpp:211:11:211:25 | call to source |
7273
| string.cpp:228:7:228:8 | s6 | string.cpp:211:11:211:25 | call to source |
74+
| string.cpp:242:10:242:16 | call to replace | string.cpp:233:17:233:22 | call to source |
7375
| string.cpp:243:7:243:8 | s4 | string.cpp:233:17:233:22 | call to source |
7476
| string.cpp:246:10:246:16 | call to replace | string.cpp:233:17:233:22 | call to source |
7577
| string.cpp:247:7:247:8 | s5 | string.cpp:233:17:233:22 | 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
@@ -62,11 +62,13 @@
6262
| string.cpp:201:10:201:15 | string.cpp:191:11:191:25 | AST only |
6363
| string.cpp:202:7:202:8 | string.cpp:191:11:191:25 | AST only |
6464
| string.cpp:205:7:205:8 | string.cpp:193:17:193:22 | AST only |
65+
| string.cpp:219:10:219:15 | string.cpp:210:17:210:22 | AST only |
6566
| string.cpp:220:7:220:8 | string.cpp:210:17:210:22 | AST only |
6667
| string.cpp:223:10:223:15 | string.cpp:210:17:210:22 | AST only |
6768
| string.cpp:224:7:224:8 | string.cpp:210:17:210:22 | AST only |
6869
| string.cpp:227:10:227:15 | string.cpp:211:11:211:25 | AST only |
6970
| string.cpp:228:7:228:8 | string.cpp:211:11:211:25 | AST only |
71+
| string.cpp:242:10:242:16 | string.cpp:233:17:233:22 | AST only |
7072
| string.cpp:243:7:243:8 | string.cpp:233:17:233:22 | AST only |
7173
| string.cpp:246:10:246:16 | string.cpp:233:17:233:22 | AST only |
7274
| string.cpp:247:7:247:8 | string.cpp:233:17:233:22 | AST only |

0 commit comments

Comments
 (0)