Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
df44348
added test cases
ethanLin520 Aug 29, 2024
50b7d0a
rename tests
ethanLin520 Sep 1, 2024
554d8a7
Merge remote-tracking branch 'root/master' into nullptr_deref_test
ethanLin520 Sep 2, 2024
fb7ef9a
modified CMakeLists.txt
ethanLin520 Sep 2, 2024
ea4bdda
modified generate_bc.sh
ethanLin520 Sep 2, 2024
e3da620
Revert "rename tests"
ethanLin520 Sep 2, 2024
5445c3a
rename successful test
ethanLin520 Sep 2, 2024
9412834
added more testcases
ethanLin520 Sep 9, 2024
9ef417f
modified ae_nullptr_deref_tests
ethanLin520 Sep 11, 2024
2f95284
added stub functions for testing in ae_nullptr_deref_stub_tests
ethanLin520 Sep 11, 2024
f7cb69d
remove recursion testcases
ethanLin520 Sep 16, 2024
3cee79f
added failed testcase folder
ethanLin520 Sep 16, 2024
80d2117
added testcases
ethanLin520 Sep 16, 2024
2bf6337
rename folder
ethanLin520 Sep 16, 2024
4fe6bf3
added comment for fail reason
ethanLin520 Sep 19, 2024
c689b65
added testcase
ethanLin520 Sep 19, 2024
4a70668
added safe access testcase
ethanLin520 Sep 19, 2024
42530ef
added testcase
ethanLin520 Sep 19, 2024
04639c2
added ae loop testcase
ethanLin520 Sep 21, 2024
6a9ed56
added more testcase for npd
ethanLin520 Sep 24, 2024
ef9bddc
removed passed cases from fail, modified failed cases
ethanLin520 Sep 24, 2024
64f3317
added some overflow testcases
ethanLin520 Sep 24, 2024
542d9b8
added new testcases for npd, rename some old testcases
ethanLin520 Sep 24, 2024
d24054a
improve naming of all testcases
ethanLin520 Sep 24, 2024
6080dac
added testcases for char *
ethanLin520 Sep 24, 2024
138fc05
added recursive testcase
Oct 5, 2024
851728c
added struct testcase
Oct 5, 2024
7dec5dc
updated CMakeLists.txt and generate_bc.sh
Oct 5, 2024
6b9773a
added more array testcases
Oct 5, 2024
da12ff4
modified option name to nullptr
ethanLin520 Oct 14, 2024
1ba0da3
moved failed tests
ethanLin520 Oct 14, 2024
758696f
Merge branch 'SVF-tools:master' into nullptr_deref_test
ethanLin520 Oct 19, 2024
34b2f70
moved failing testcases
ethanLin520 Oct 21, 2024
4528c7e
deleted failing testcases bc file
ethanLin520 Oct 21, 2024
86107f6
added testcase for malloc
ethanLin520 Nov 3, 2024
f17f4ad
moved failed testcases
ethanLin520 Nov 3, 2024
373d4bf
moved successful testcases back
ethanLin520 Nov 4, 2024
4aba940
added testcases for dangling pointer dereference
ethanLin520 Nov 17, 2024
582124a
Merge branch 'SVF-tools:master' into nullptr_deref_test
ethanLin520 Dec 15, 2024
b555bbe
Rename directory
ethanLin520 Dec 15, 2024
3238196
Organize test dir
ethanLin520 Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,16 @@ foreach(filename ${ae_overflow_files})
)
endforeach()

# loops over ae_nullptr_files and run "ae $bc_file"
file(GLOB ae_nullptr_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/test_cases_bc/ae_nullptr_deref_tests/*.bc")

foreach(filename ${ae_nullptr_files})
add_test(
NAME ae_nullptr/${filename}
COMMAND ae -nullptr ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
endforeach()

## symbolic abstraction tests (ctest -R symabs -VV)
set(cmd "ae -symabs")
Expand Down
1 change: 1 addition & 0 deletions generate_bc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ test_dirs="
objtype_tests
ae_overflow_tests
ae_assert_tests
ae_nullptr_deref_tests
"


Expand Down
12 changes: 12 additions & 0 deletions src/ae_assert_tests/LOOP_while01-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "stdbool.h"
extern void svf_assert(bool);

int main(){
int x;
x=10;
while(x>0) {
x--;
}
svf_assert(x == 0);
return 0;
}
12 changes: 12 additions & 0 deletions src/ae_assert_tests/LOOP_while02-0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "stdbool.h"
extern void svf_assert(bool);

int main(){
int x;
x=1;
while(x<128) {
x*=2;
}
svf_assert(x == 128);
return 0;
}
12 changes: 12 additions & 0 deletions src/ae_assert_tests/LOOP_while02-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "stdbool.h"
extern void svf_assert(bool);

int main(){
int x;
x=128;
while(x>4) {
x/=2;
}
svf_assert(x == 4);
return 0;
}
23 changes: 23 additions & 0 deletions src/ae_nullptr_deref_tests/array_2d_big.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

#define SIZE 100

int main() {
int *arr[SIZE][SIZE];

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
arr[i][j] = NULL;
}
}

for (int m = 0; m < SIZE; m++) {
for (int n = 0; n < SIZE; n++) {
UNSAFE_LOAD(arr[m][n]);
}
}

return 0;
}
16 changes: 16 additions & 0 deletions src/ae_nullptr_deref_tests/array_2d_small.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
int *arr[2][2];
arr[0][0] = NULL;
arr[0][1] = NULL;
arr[1][0] = NULL;
arr[1][1] = NULL;

UNSAFE_LOAD(arr[0][0]);
UNSAFE_LOAD(arr[0][1]);
UNSAFE_LOAD(arr[1][0]);
UNSAFE_LOAD(arr[1][1]);
}
21 changes: 21 additions & 0 deletions src/ae_nullptr_deref_tests/array_2d_small_partial_null.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <stdlib.h>

extern void SAFE_LOAD(void *ptr);
extern void UNSAFE_LOAD(void *ptr);

int main() {
int *arr[2][2];
arr[0][0] = NULL;
arr[0][1] = NULL;
arr[1][0] = malloc(sizeof(int));
arr[1][1] = malloc(sizeof(int));

*arr[1][0] = 123;
*arr[1][1] = 456;

UNSAFE_LOAD(arr[0][0]);
UNSAFE_LOAD(arr[0][1]);
SAFE_LOAD(arr[1][0]);
SAFE_LOAD(arr[1][1]);
}
13 changes: 13 additions & 0 deletions src/ae_nullptr_deref_tests/array_all_nullptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
int *n = NULL;
int *ptrs[5] = {n, n, n, n, n};
for (int i = 0; i < 5; i++) {
UNSAFE_LOAD(ptrs[i]);
}

return 0;
}
23 changes: 23 additions & 0 deletions src/ae_nullptr_deref_tests/array_of_struct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdlib.h>

extern void SAFE_LOAD(void *ptr);
extern void UNSAFE_LOAD(void *ptr);

struct S {
int *intPtr;
};

int main() {
struct S arrStruct[3];

arrStruct[0].intPtr = malloc(sizeof(int));
*arrStruct[0].intPtr = 1024;

arrStruct[1].intPtr = NULL;

SAFE_LOAD(arrStruct[0].intPtr); // malloc
UNSAFE_LOAD(arrStruct[1].intPtr); // NULL
UNSAFE_LOAD(arrStruct[2].intPtr); // uninitialized

return 0;
}
15 changes: 15 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_arg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

void foo(char *ptr) {
UNSAFE_LOAD(ptr); // Dereferencing the NULL pointer
}

int main() {
char *ptr = NULL;

foo(ptr); // Passing a NULL pointer to the function

return 0;
}
13 changes: 13 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_arithmetic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
char *ptr = NULL;

char *newPtr = ptr + 5; // Perform pointer arithmetic on NULL pointer

UNSAFE_LOAD(newPtr); // Dereference the result

return 0;
}
18 changes: 18 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_branch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
char *ptr = (char *)malloc(sizeof(char)); // Allocate memory

int a = 0;

if (a >= 0) {
ptr = NULL;
}

UNSAFE_LOAD(ptr);

return 0;
}
11 changes: 11 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_doubleptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {

char **double_ptr = NULL;
UNSAFE_LOAD(double_ptr); // This will trigger a null pointer dereference

return 0;
}
15 changes: 15 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_func_return_val.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

char *getNullPointer() {
return NULL; // Function returns a NULL pointer
}

int main() {
char *ptr = getNullPointer();

UNSAFE_LOAD(ptr);

return 0;
}
20 changes: 20 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_in_struct_null.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Created by Ethan Lin on 30/9/2024.
//

#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

struct S {
char *ptr;
};

int main() {
struct S myStruct;
myStruct.ptr = NULL;

UNSAFE_LOAD(myStruct.ptr);

return 0;
}
19 changes: 19 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_in_struct_uninitialized.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// Created by Ethan Lin on 30/9/2024.
//

#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

struct S {
char *ptr;
};

int main() {
struct S myStruct;

UNSAFE_LOAD(myStruct.ptr);

return 0;
}
20 changes: 20 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_indirect_func_return_val.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>

extern void UNSAFE_LOAD(void *ptr);

char *getNullPointer() {
return NULL; // Function returns a NULL pointer
}

char *foo() {
char *p = getNullPointer();
return p;
}

int main() {
char *ptr = foo();

UNSAFE_LOAD(ptr); // Dereferencing the NULL pointer

return 0;
}
11 changes: 11 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_partial_nullptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdlib.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
char *p = malloc(sizeof(char) * 100);
*p = 'This string can be stored.';
free(p);
p = NULL;
UNSAFE_LOAD(p);
}
8 changes: 8 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdlib.h>

extern void UNSAFE_LOAD(void *ptr);

int main() {
char *p = NULL;
UNSAFE_LOAD(p);
}
7 changes: 7 additions & 0 deletions src/ae_nullptr_deref_tests/char_ptr_uninit_ptr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

extern void UNSAFE_LOAD(void *ptr);

int main() {
char *p;
UNSAFE_LOAD(p);
}
28 changes: 28 additions & 0 deletions src/ae_nullptr_deref_tests/dangleptr_safe_branch.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by Ethan Lin on 11/11/2024.
//

#include <stdlib.h>

extern void SAFE_LOAD(void *p);
extern void UNSAFE_LOAD(void *p);

int main() {
int a = 5;

int *myPtr;

myPtr = (int*)malloc(sizeof(int));
free(myPtr);
UNSAFE_LOAD(myPtr);
if (a > 0)
{
myPtr = &a;
} else
{
/* Do nothing */
}

SAFE_LOAD(myPtr);
return 0;
}
21 changes: 21 additions & 0 deletions src/ae_nullptr_deref_tests/dangleptr_safe_free_and_reassign.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by Ethan Lin on 11/11/2024.
//

#include <stdlib.h>

extern void SAFE_LOAD(void *p);
extern void UNSAFE_LOAD(void *p);

int main() {
int a = 5;

int *myPtr;

myPtr = (int*)malloc(sizeof(int));
free(myPtr);
// UNSAFE_LOAD(myPtr);
myPtr = &a;
SAFE_LOAD(myPtr);
return 0;
}
Loading