Skip to content

Commit ee8ce1c

Browse files
authored
Merge pull request github#18222 from github/calumgrant/bmn/badly-bounded-write
C++: Fix FPs in cpp/badly-bounded-write caused by extraction errors
2 parents fa123a7 + e98129c commit ee8ce1c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

cpp/ql/src/Security/CWE/CWE-120/BadlyBoundedWrite.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ from BufferWrite bw, int destSize
2525
where
2626
bw.hasExplicitLimit() and // has an explicit size limit
2727
destSize = max(getBufferSize(bw.getDest(), _)) and
28-
bw.getExplicitLimit() > destSize // but it's larger than the destination
28+
bw.getExplicitLimit() > destSize and // but it's larger than the destination
29+
not bw.getDest().getType().stripType() instanceof ErroneousType // destSize may be incorrect
2930
select bw,
3031
"This '" + bw.getBWDesc() + "' operation is limited to " + bw.getExplicitLimit() +
3132
" bytes but the destination is only " + destSize + " bytes."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Badly bounded write" query (`cpp/badly-bounded-write`) no longer produces results if there is an extraction error in the type of the output buffer.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
typedef unsigned long size_t;
4+
typedef int wchar_t;
5+
6+
int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...);
7+
8+
void test_extraction_errors() {
9+
WCHAR buffer[3];
10+
swprintf(buffer, 3, L"abc");
11+
}

0 commit comments

Comments
 (0)