Skip to content

Commit d9665e1

Browse files
committed
C++: add case test for constant off-by-one query
1 parent 3abf5d1 commit d9665e1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/constant-size/ConstantSizeArrayOffByOne.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ edges
3333
| test.cpp:77:32:77:34 | buf | test.cpp:77:27:77:34 | buf |
3434
| test.cpp:79:27:79:34 | buf | test.cpp:70:33:70:33 | p |
3535
| test.cpp:79:32:79:34 | buf | test.cpp:79:27:79:34 | buf |
36+
| test.cpp:85:34:85:36 | buf | test.cpp:87:5:87:11 | charBuf |
37+
| test.cpp:85:34:85:36 | buf | test.cpp:88:5:88:11 | charBuf |
38+
| test.cpp:87:5:87:11 | charBuf | test.cpp:87:5:87:31 | access to array |
39+
| test.cpp:88:5:88:11 | charBuf | test.cpp:88:5:88:27 | access to array |
3640
nodes
3741
| test.cpp:26:5:26:12 | buf | semmle.label | buf |
3842
| test.cpp:26:10:26:12 | buf | semmle.label | buf |
@@ -84,6 +88,11 @@ nodes
8488
| test.cpp:77:32:77:34 | buf | semmle.label | buf |
8589
| test.cpp:79:27:79:34 | buf | semmle.label | buf |
8690
| test.cpp:79:32:79:34 | buf | semmle.label | buf |
91+
| test.cpp:85:34:85:36 | buf | semmle.label | buf |
92+
| test.cpp:87:5:87:11 | charBuf | semmle.label | charBuf |
93+
| test.cpp:87:5:87:31 | access to array | semmle.label | access to array |
94+
| test.cpp:88:5:88:11 | charBuf | semmle.label | charBuf |
95+
| test.cpp:88:5:88:27 | access to array | semmle.label | access to array |
8796
subpaths
8897
#select
8998
| test.cpp:35:5:35:22 | access to array | test.cpp:35:10:35:12 | buf | test.cpp:35:5:35:22 | access to array | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:35:5:35:26 | Store: ... = ... | write |
@@ -98,3 +107,5 @@ subpaths
98107
| test.cpp:77:27:77:44 | access to array | test.cpp:77:32:77:34 | buf | test.cpp:66:32:66:32 | p | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
99108
| test.cpp:77:27:77:44 | access to array | test.cpp:77:32:77:34 | buf | test.cpp:67:5:67:6 | * ... | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
100109
| test.cpp:77:27:77:44 | access to array | test.cpp:77:32:77:34 | buf | test.cpp:67:6:67:6 | p | This pointer arithmetic may have an off-by-1 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:67:5:67:10 | Store: ... = ... | write |
110+
| test.cpp:87:5:87:31 | access to array | test.cpp:85:34:85:36 | buf | test.cpp:87:5:87:31 | access to array | This pointer arithmetic may have an off-by-3072 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:87:5:87:35 | Store: ... = ... | write |
111+
| test.cpp:88:5:88:27 | access to array | test.cpp:85:34:85:36 | buf | test.cpp:88:5:88:27 | access to array | This pointer arithmetic may have an off-by-3073 error allowing it to overrun $@ at this $@. | test.cpp:15:9:15:11 | buf | buf | test.cpp:88:5:88:31 | Store: ... = ... | write |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-193/constant-size/test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,12 @@ void testInterproc(BigArray *arr) {
7878

7979
addToPointerAndAssign(arr->buf);
8080
}
81+
82+
#define MAX_SIZE_BYTES 4096
83+
84+
void testCharIndex(BigArray *arr) {
85+
char *charBuf = (char*) arr->buf;
86+
87+
charBuf[MAX_SIZE_BYTES - 1] = 0; // GOOD [FALSE POSITIVE]
88+
charBuf[MAX_SIZE_BYTES] = 0; // BAD
89+
}

0 commit comments

Comments
 (0)