File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed
test/query-tests/Security/CWE/CWE-014 Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 3232 forall ( Expr escape | variableAddressEscapesTree ( v .getAnAccess ( ) , escape ) |
3333 call .getArgument ( 0 ) = escape .getUnconverted ( )
3434 ) and
35- // `v` is a stack-allocated array or a struct.
35+ // `v` is a stack-allocated array or a struct, and `v` is not static.
36+ not v .isStatic ( ) and
3637 (
3738 v .getUnspecifiedType ( ) instanceof ArrayType and call .getArgument ( 0 ) = v .getAnAccess ( )
3839 or
Original file line number Diff line number Diff line change @@ -59,9 +59,9 @@ int func1d() {
5959 memset (pw1d , 0 , PW_SIZE ); // GOOD
6060 return 0 ;
6161}
62- // x86-64 gcc 9.2: not deleted
63- // x86-64 clang 9.0.0: not deleted
64- // x64 msvc v19.14 (WINE): not deleted
62+ // x86-64 gcc 9.2: deleted
63+ // x86-64 clang 9.0.0: deleted
64+ // x64 msvc v19.14 (WINE): deleted
6565char * func2 (void ) {
6666 char pw2 [PW_SIZE ];
6767 use_pw (pw2 );
@@ -129,9 +129,9 @@ int func8(void) {
129129 return pw1a [4 ];
130130}
131131
132- // x86-64 gcc 9.2: not deleted
133- // x86-64 clang 9.0.0: not deleted
134- // x64 msvc v19.14 (WINE): not deleted
132+ // x86-64 gcc 9.2: deleted
133+ // x86-64 clang 9.0.0: deleted
134+ // x64 msvc v19.14 (WINE): deleted
135135char * func9 (void ) {
136136 char pw1 [PW_SIZE ];
137137 use_pw (pw1 );
Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ bool nobadFunc2_1_0(unsigned char ch){
277277
278278void nobadFunc2_1_2 (){
279279 unsigned char buff1[PW_SIZE];
280- memset (buff1, 0 , PW_SIZE); // GOOD
280+ memset (buff1, 0 , PW_SIZE); // BAD [NOT DETECTED]
281281 buff1[2 ] = 5 ;
282282}
283283
@@ -364,3 +364,11 @@ void nobadFunc4_6(){
364364 unsigned char * buff1 = globalBuff2->buff2 ;
365365 memset (buff1, 0 , PW_SIZE); // GOOD
366366}
367+
368+ extern void use_byte (unsigned char );
369+
370+ void test_static_func () {
371+ static unsigned char buffer[PW_SIZE] = {0 };
372+ use_byte (buffer[0 ]);
373+ memset (buffer, 42 , sizeof (buffer)); // GOOD
374+ }
You can’t perform that action at this time.
0 commit comments