Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add regression test for missing init() in realloc() #221

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ overflow_small_1_byte
overflow_small_8_byte
uninitialized_read_large
uninitialized_read_small
realloc_init
__pycache__/
3 changes: 2 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ EXECUTABLES := \
malloc_object_size_offset \
invalid_malloc_object_size_small \
invalid_malloc_object_size_small_quarantine \
impossibly_large_malloc
impossibly_large_malloc \
realloc_init

all: $(EXECUTABLES)

Expand Down
33 changes: 33 additions & 0 deletions test/realloc_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <pthread.h>
#include <stdlib.h>


static void* thread_func(void *arg) {
arg = realloc(arg, 1024);
if (!arg)
exit(EXIT_FAILURE);

free(arg);

return NULL;
}

int main(void) {
void *mem;
pthread_t thread;
int r;

mem = realloc(NULL, 12);
if (!mem)
return EXIT_FAILURE;

r = pthread_create(&thread, NULL, thread_func, mem);
if (r != 0)
return EXIT_FAILURE;

r = pthread_join(thread, NULL);
if (r != 0)
return EXIT_FAILURE;

return EXIT_SUCCESS;
}
5 changes: 5 additions & 0 deletions test/test_smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ def test_uninitialized_read_large(self):
"uninitialized_read_large")
self.assertEqual(returncode, 0)

def test_realloc_init(self):
_stdout, _stderr, returncode = self.run_test(
"realloc_init")
self.assertEqual(returncode, 0)


if __name__ == '__main__':
unittest.main()