mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-05-27 18:22:18 -04:00
test: add tests for zero sized realloc(3)
C23 declared calling realloc(3) with a non-NULL pointer and zero size Undefined behavior. Check that hardened_malloc handles that case sanely by free'ing the old pointer and returning a special pointer, like `malloc(3)` called with size zero.
This commit is contained in:
parent
1d7fc7ffe0
commit
9ca3279507
6 changed files with 80 additions and 1 deletions
19
test/realloc_c23_undefined_behaviour.c
Normal file
19
test/realloc_c23_undefined_behaviour.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test_util.h"
|
||||
|
||||
OPTNONE int main(void) {
|
||||
char *p, *q, *r;
|
||||
|
||||
p = malloc(16);
|
||||
if (!p) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
q = realloc(p, 0);
|
||||
|
||||
free(q);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue