Skip to content

Commit ff46e2c

Browse files
authored
Merge pull request github#16662 from jketema/gets
C++: Ignore `gets`'es with incorrect parameter counts
2 parents 63bec5a + 6f8449c commit ff46e2c

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

cpp/ql/src/Security/CWE/CWE-676/DangerousFunctionOverflow.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ import cpp
1717
from FunctionCall call, Function target
1818
where
1919
call.getTarget() = target and
20-
target.hasGlobalOrStdName("gets")
20+
target.hasGlobalOrStdName("gets") and
21+
target.getNumberOfParameters() = 1
2122
select call, "'gets' does not guard against buffer overflow."
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 `cpp/dangerous-function-overflow` no longer produces a false positive alert when the `gets` function does not have exactly one parameter.

cpp/ql/test/query-tests/Security/CWE/CWE-676/semmle/PotentiallyDangerousFunction/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ char *gets(char *s);
3636

3737
void testGets() {
3838
char buf1[1024];
39-
char buf2 = malloc(1024);
39+
char *buf2 = malloc(1024);
4040
char *s;
4141

4242
gets(buf1); // BAD: use of gets
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
char *gets();
2+
3+
void testOtherGets() {
4+
char *s;
5+
6+
s = gets(); // GOOD: this is not the gets from stdio.h
7+
}

0 commit comments

Comments
 (0)