Skip to content

Commit 5637d57

Browse files
committed
C++: Add test case that is no longer detected after latest changes
1 parent 6dbc59d commit 5637d57

File tree

2 files changed

+11
-2
lines changed
  • cpp/ql/test/query-tests/Security/CWE/CWE-022/semmle/tests

2 files changed

+11
-2
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-022/semmle/tests/stdlib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
typedef struct {} FILE;
77
#define FILENAME_MAX 1000
88
typedef unsigned long size_t;
9-
#define NULL ((void*)0)
109

1110
FILE *fopen(const char *filename, const char *mode);
1211
int sprintf(char *s, const char *format, ...);
@@ -15,3 +14,4 @@ char *strncat(char *s1, const char *s2, size_t n);
1514
int scanf(const char *format, ...);
1615
void *malloc(size_t size);
1716
double strtod(const char *ptr, char **endptr);
17+
char *getenv(const char *name);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(int argc, char** argv) {
3939
}
4040

4141
{
42-
char *fileName = malloc(20 * sizeof(char));
42+
char *fileName = (char*)malloc(20 * sizeof(char));
4343
scanf("%s", fileName);
4444
fopen(fileName, "wb+"); // BAD
4545
}
@@ -51,4 +51,13 @@ int main(int argc, char** argv) {
5151
sprintf(fileName, "/foo/%f", number);
5252
fopen(fileName, "wb+"); // GOOD
5353
}
54+
55+
{
56+
void read(const char *fileName);
57+
read(argv[1]); // BAD [NOT DETECTED]
58+
}
59+
}
60+
61+
void read(char *fileName) {
62+
fopen(fileName, "wb+");
5463
}

0 commit comments

Comments
 (0)