Skip to content

Commit c3f2faf

Browse files
committed
C++: Add another pattern I found in the wild.
1 parent a9f6b21 commit c3f2faf

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cpp/ql/test/query-tests/Critical/MissingCheckScanf/IncorrectCheckScanf.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
| test.cpp:443:11:443:15 | call to scanf | The result of scanf is only checked against 0, but it can also return EOF. |
66
| test.cpp:501:13:501:17 | call to scanf | The result of scanf is only checked against 0, but it can also return EOF. |
77
| test.cpp:512:13:512:17 | call to scanf | The result of scanf is only checked against 0, but it can also return EOF. |
8+
| test.cpp:525:10:525:15 | call to sscanf | The result of scanf is only checked against 0, but it can also return EOF. |
9+
| test.cpp:541:10:541:15 | call to sscanf | The result of scanf is only checked against 0, but it can also return EOF. |

cpp/ql/test/query-tests/Critical/MissingCheckScanf/test.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,38 @@ void multiple_checks() {
518518
}
519519
}
520520
}
521+
522+
void switch_cases(const char *data) {
523+
float a, b, c;
524+
525+
switch (sscanf(data, "%f %f %f", &a, &b, &c)) { // [FALSE POSITIVE]
526+
case 2:
527+
use(a); // GOOD
528+
use(b); // GOOD
529+
break;
530+
case 3:
531+
use(a); // GOOD
532+
use(b); // GOOD
533+
use(c); // GOOD
534+
break;
535+
default:
536+
break;
537+
}
538+
539+
float d, e, f;
540+
541+
switch (sscanf(data, "%f %f %f", &d, &e, &f)) { // [REPORTED HERE]
542+
case 2:
543+
use(d); // GOOD
544+
use(e); // GOOD
545+
use(f); // BAD
546+
break;
547+
case 3:
548+
use(d); // GOOD
549+
use(e); // GOOD
550+
use(f); // GOOD
551+
break;
552+
default:
553+
break;
554+
}
555+
}

0 commit comments

Comments
 (0)