Skip to content

Commit c41add8

Browse files
committed
C++: Accept regressions in SAMATE based test cases.
1 parent a7ac6b1 commit c41add8

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| tests.cpp:45:9:45:14 | call to memcpy | This 'memcpy' operation accesses 32 bytes but the $@ is only 16 bytes. | tests.cpp:32:10:32:18 | charFirst | destination buffer |
2-
| tests.cpp:60:9:60:14 | call to memcpy | This 'memcpy' operation accesses 32 bytes but the $@ is only 16 bytes. | tests.cpp:32:10:32:18 | charFirst | destination buffer |
31
| tests.cpp:171:9:171:14 | call to memcpy | This 'memcpy' operation accesses 100 bytes but the $@ is only 50 bytes. | tests.cpp:164:20:164:25 | call to malloc | destination buffer |
42
| tests.cpp:172:9:172:19 | access to array | This array indexing operation accesses byte offset 99 but the $@ is only 50 bytes. | tests.cpp:164:20:164:25 | call to malloc | array |
53
| tests.cpp:192:9:192:14 | call to memcpy | This 'memcpy' operation accesses 100 bytes but the $@ is only 50 bytes. | tests.cpp:181:10:181:22 | dataBadBuffer | destination buffer |
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
| tests.cpp:45:51:45:72 | sizeof(<expr>) | Potential buffer-overflow: 'charFirst' has size 16 not 32. |
2-
| tests.cpp:60:52:60:74 | sizeof(<expr>) | Potential buffer-overflow: 'charFirst' has size 16 not 32. |

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CWE121_Stack_Based_Buffer_Overflow__char_type_overrun_memcpy_01_bad()
4242
/* Print the initial block pointed to by structCharVoid.voidSecond */
4343
printLine((char *)structCharVoid.voidSecond);
4444
/* FLAW: Use the sizeof(structCharVoid) which will overwrite the pointer voidSecond */
45-
memcpy(structCharVoid.charFirst, SRC_STR, sizeof(structCharVoid));
45+
memcpy(structCharVoid.charFirst, SRC_STR, sizeof(structCharVoid)); // [NOT DETECTED]
4646
structCharVoid.charFirst[(sizeof(structCharVoid.charFirst)/sizeof(char))-1] = '\0'; /* null terminate the string */
4747
printLine((char *)structCharVoid.charFirst);
4848
printLine((char *)structCharVoid.voidSecond);
@@ -57,7 +57,7 @@ void CWE122_Heap_Based_Buffer_Overflow__char_type_overrun_memcpy_01_bad()
5757
/* Print the initial block pointed to by structCharVoid->voidSecond */
5858
printLine((char *)structCharVoid->voidSecond);
5959
/* FLAW: Use the sizeof(*structCharVoid) which will overwrite the pointer y */
60-
memcpy(structCharVoid->charFirst, SRC_STR, sizeof(*structCharVoid));
60+
memcpy(structCharVoid->charFirst, SRC_STR, sizeof(*structCharVoid)); // [NOT DETECTED]
6161
structCharVoid->charFirst[(sizeof(structCharVoid->charFirst)/sizeof(char))-1] = '\0'; /* null terminate the string */
6262
printLine((char *)structCharVoid->charFirst);
6363
printLine((char *)structCharVoid->voidSecond);
@@ -292,7 +292,7 @@ namespace CWE122_Heap_Based_Buffer_Overflow__cpp_CWE193_wchar_t_ncpy_01
292292
delete [] data;
293293
}
294294
}
295-
295+
296296
static void goodG2B()
297297
{
298298
wchar_t * data;
@@ -459,7 +459,7 @@ void CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_ncpy_01_bad()
459459
#ifdef _WIN32
460460
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format, ...);
461461
#define SNPRINTF _snwprintf
462-
#else
462+
#else
463463
int snprintf(char *s, size_t n, const char *format, ...);
464464
int swprintf(wchar_t *wcs, size_t maxlen, const wchar_t *format, ...);
465465
//#define SNPRINTF snprintf --- original code; using snprintf appears to be a mistake in samate?
@@ -485,14 +485,14 @@ void CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_snprintf_01_bad()
485485
}
486486

487487
/* classes used in some test cases as a custom type */
488-
class TwoIntsClass
488+
class TwoIntsClass
489489
{
490490
public: // Needed to access variables from label files
491491
int intOne;
492492
int intTwo;
493493
};
494494

495-
class OneIntClass
495+
class OneIntClass
496496
{
497497
public: // Needed to access variables from label files
498498
int intOne;
@@ -636,7 +636,7 @@ void CWE122_Heap_Based_Buffer_Overflow__cpp_CWE805_wchar_t_snprintf_31_bad()
636636

637637
int rand(void);
638638

639-
int globalReturnsTrueOrFalse()
639+
int globalReturnsTrueOrFalse()
640640
{
641641
return (rand() % 2);
642642
}

0 commit comments

Comments
 (0)