Skip to content

Commit

Permalink
Add a few CWE-562 test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstanb committed Nov 20, 2023
1 parent 3a8b1b0 commit 4567e32
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/regression/74-invalid_deref/30-cwe-562-nested-globals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdlib.h>

char **a;
char *globb;

char *cwe() {
globb = malloc(sizeof(char));
a = malloc(sizeof(char*));
*a = globb;
// TODO: Not sure why we still get a warn for the line below. Need to fix it
return *a; //NOWARN
}

int main(int argc, char const *argv[]) {
char *b = cwe();
char test = *b;
return 0;
}
12 changes: 12 additions & 0 deletions tests/regression/74-invalid_deref/31-cwe-562-address-taken.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdlib.h>

char *cwe() {
char a;
return &a; //WARN
}

int main(int argc, char const *argv[]) {
char *b = cwe();
char test = *b; //WARN
return 0;
}
12 changes: 12 additions & 0 deletions tests/regression/74-invalid_deref/32-cwe-562-local-ptr-var.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdlib.h>

char *cwe() {
char *a;
return a; //WARN
}

int main(int argc, char const *argv[]) {
char *b = cwe();
char test = *b; //WARN
return 0;
}
16 changes: 16 additions & 0 deletions tests/regression/74-invalid_deref/33-cwe-562-global-local.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdlib.h>

char **a;

char *cwe() {
char *local;
a = malloc(sizeof(char*));
*a = local;
return *a; //WARN
}

int main(int argc, char const *argv[]) {
char *b = cwe();
char test = *b; //WARN
return 0;
}

0 comments on commit 4567e32

Please sign in to comment.