Skip to content

Commit 6ca978e

Browse files
committed
C++: Add FP test.
1 parent 823d5ac commit 6ca978e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-129/semmle/ImproperArrayIndexValidation/ImproperArrayIndexValidation.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ edges
1313
| test1.c:42:16:42:16 | i | test1.c:43:11:43:11 | i | provenance | |
1414
| test1.c:50:16:50:16 | i | test1.c:53:3:53:7 | ... = ... | provenance | |
1515
| test1.c:53:3:53:7 | ... = ... | test1.c:55:15:55:15 | j | provenance | |
16+
| test1.c:76:11:76:23 | ... = ... | test1.c:77:20:77:21 | ch | provenance | |
17+
| test1.c:76:16:76:19 | call to getc | test1.c:76:11:76:23 | ... = ... | provenance | |
1618
nodes
1719
| test1.c:7:26:7:29 | **argv | semmle.label | **argv |
1820
| test1.c:8:11:8:14 | call to atoi | semmle.label | call to atoi |
@@ -29,9 +31,13 @@ nodes
2931
| test1.c:50:16:50:16 | i | semmle.label | i |
3032
| test1.c:53:3:53:7 | ... = ... | semmle.label | ... = ... |
3133
| test1.c:55:15:55:15 | j | semmle.label | j |
34+
| test1.c:76:11:76:23 | ... = ... | semmle.label | ... = ... |
35+
| test1.c:76:16:76:19 | call to getc | semmle.label | call to getc |
36+
| test1.c:77:20:77:21 | ch | semmle.label | ch |
3237
subpaths
3338
#select
3439
| test1.c:20:16:20:16 | i | test1.c:7:26:7:29 | **argv | test1.c:20:16:20:16 | i | An array indexing expression depends on $@ that might be outside the bounds of the array. | test1.c:7:26:7:29 | **argv | a command-line argument |
3540
| test1.c:35:11:35:11 | i | test1.c:7:26:7:29 | **argv | test1.c:35:11:35:11 | i | An array indexing expression depends on $@ that might be outside the bounds of the array. | test1.c:7:26:7:29 | **argv | a command-line argument |
3641
| test1.c:43:11:43:11 | i | test1.c:7:26:7:29 | **argv | test1.c:43:11:43:11 | i | An array indexing expression depends on $@ that might be outside the bounds of the array. | test1.c:7:26:7:29 | **argv | a command-line argument |
3742
| test1.c:55:15:55:15 | j | test1.c:7:26:7:29 | **argv | test1.c:55:15:55:15 | j | An array indexing expression depends on $@ that might be outside the bounds of the array. | test1.c:7:26:7:29 | **argv | a command-line argument |
43+
| test1.c:77:20:77:21 | ch | test1.c:76:16:76:19 | call to getc | test1.c:77:20:77:21 | ch | An array indexing expression depends on $@ that might be outside the bounds of the array. | test1.c:76:16:76:19 | call to getc | external |

cpp/ql/test/query-tests/Security/CWE/CWE-129/semmle/ImproperArrayIndexValidation/test1.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,17 @@ void test6(int i) {
6363
myTable[s] = 0; // GOOD: Input is small [FALSE POSITIVE]
6464
}
6565

66-
void test7(char *s) { }
66+
typedef void FILE;
67+
#define EOF (-1)
68+
69+
int getc(FILE*);
70+
71+
extern int myMaxCharTable[256];
72+
73+
void test7(FILE* fp) {
74+
int ch;
75+
while ((ch = getc(fp)) != EOF) {
76+
myMaxCharTable[ch] = 0; // GOOD [FALSE POSITIVE]
77+
}
78+
}
79+

0 commit comments

Comments
 (0)