Skip to content

Commit 8935599

Browse files
committed
C++: Additional test cases.
1 parent e77ebf0 commit 8935599

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/OverflowBuffer.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
| tests.cpp:363:2:363:16 | access to array | This array indexing operation accesses byte offset 219 but the $@ is only 200 bytes. | tests.cpp:344:11:344:21 | structArray | array |
3030
| tests.cpp:364:25:364:39 | access to array | This array indexing operation accesses byte offset 219 but the $@ is only 200 bytes. | tests.cpp:344:11:344:21 | structArray | array |
3131
| tests.cpp:367:23:367:34 | access to array | This array indexing operation accesses byte offset 43 but the $@ is only 40 bytes. | tests.cpp:343:6:343:13 | intArray | array |
32+
| tests.cpp:369:2:369:13 | access to array | This array indexing operation accesses a negative index -2 on the $@. | tests.cpp:342:7:342:15 | charArray | array |
33+
| tests.cpp:370:2:370:13 | access to array | This array indexing operation accesses a negative index -1 on the $@. | tests.cpp:342:7:342:15 | charArray | array |
34+
| tests.cpp:374:2:374:13 | access to array | This array indexing operation accesses byte offset 10 but the $@ is only 10 bytes. | tests.cpp:342:7:342:15 | charArray | array |
3235
| tests.cpp:394:3:394:13 | access to array | This array indexing operation accesses byte offset 101 but the $@ is only 100 bytes. | tests.cpp:389:47:389:52 | call to malloc | array |
3336
| tests.cpp:397:3:397:13 | access to array | This array indexing operation accesses byte offset 101 but the $@ is only 101 bytes. | tests.cpp:390:47:390:52 | call to malloc | array |
3437
| tests.cpp:467:3:467:24 | access to array | This array indexing operation accesses a negative index -3 on the $@. | tests.cpp:465:7:465:14 | intArray | array |

cpp/ql/test/query-tests/Security/CWE/CWE-119/semmle/tests/tests.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@ void test12()
337337
}
338338
}
339339

340-
void test13()
340+
void test13(char *argArray)
341341
{
342342
char charArray[10];
343343
int intArray[10];
344344
myStruct structArray[10];
345-
346-
345+
char *ptrArray = charArray;
346+
char *ptrArrayOffset = charArray + 1;
347347

348348
charArray[-1] = 1; // BAD: underrun write
349349
charArray[0] = 1; // GOOD
@@ -366,24 +366,24 @@ void test13()
366366
charArray[9] = (char)intArray[9]; // GOOD
367367
charArray[9] = (char)intArray[10]; // BAD: overrun read
368368

369-
370-
371-
372-
373-
374-
375-
376-
377-
378-
379-
380-
381-
382-
383-
384-
385-
386-
369+
ptrArray[-2] = 1; // BAD: underrun write
370+
ptrArray[-1] = 1; // BAD: underrun write
371+
ptrArray[0] = 1; // GOOD
372+
ptrArray[8] = 1; // GOOD
373+
ptrArray[9] = 1; // GOOD
374+
ptrArray[10] = 1; // BAD: overrun write
375+
376+
ptrArrayOffset[-2] = 1; // BAD: underrun write [NOT DETECTED]
377+
ptrArrayOffset[-1] = 1; // GOOD (there is room for this)
378+
ptrArrayOffset[0] = 1; // GOOD
379+
ptrArrayOffset[8] = 1; // GOOD
380+
ptrArrayOffset[9] = 1; // BAD: overrun write [NOT DETECTED]
381+
ptrArrayOffset[10] = 1; // BAD: overrun write [NOT DETECTED]
382+
383+
argArray[-1] = 1; // BAD: underrun write [NOT DETECTED]
384+
argArray[0] = 1; // GOOD
385+
argArray[1] = 1; // GOOD (we can't tell the length of this array)
386+
argArray[999] = 1; // GOOD (we can't tell the length of this array)
387387

388388
{
389389
unsigned short *buffer1 = (unsigned short *)malloc(sizeof(short) * 50);

0 commit comments

Comments
 (0)