Skip to content

Commit fcdce55

Browse files
authored
Merge pull request #21857 from MathiasVP/fix-cleartext-fp
C++: Fix FP on `cpp/cleartext-transmission`
2 parents 76f71dd + 8ce601b commit fcdce55

4 files changed

Lines changed: 19 additions & 0 deletions

File tree

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 `RemoteFlowSourceFunction` model for `fscanf` (and variants) now implements `hasSocketInput` to reflect that these functions may read from a socket.

cpp/ql/lib/semmle/code/cpp/models/implementations/Scanf.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ private class FscanfModel extends ScanfFunctionModel, RemoteFlowSourceFunction i
8787
output.isParameterDeref(any(int i | i >= this.getArgsStartPosition())) and
8888
description = "value read by " + this.getName()
8989
}
90+
91+
override predicate hasSocketInput(FunctionInput input) {
92+
input.isParameterDeref(super.getInputParameterIndex())
93+
}
9094
}
9195

9296
/**
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 'Cleartext transmission of sensitive information' query (`cpp/cleartext-transmission`) no longer raises an alert on calls to `fscanf` (and variants) when the call reads from an "obviously local" `FILE` stream such as `stdin`.

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,10 @@ void tests3()
577577
str = get_home_address();
578578
send(val(), str, strlen(str), val()); // BAD
579579
}
580+
581+
int fscanf(FILE* stream, const char* format, ... );
582+
583+
void test_scanf() {
584+
char password[256];
585+
fscanf(stdin, "%255s", password); // GOOD: this is not a remote source
586+
}

0 commit comments

Comments
 (0)