Skip to content

Commit 66077dc

Browse files
committed
C++: Ignore gets'es with incorrect parameter counts
1 parent a83d500 commit 66077dc

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-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."

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)