mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2024-12-25 15:39:30 -05:00
add simple string overflow test
This commit is contained in:
parent
b24569b6ca
commit
93fcc6a978
@ -20,6 +20,7 @@ EXECUTABLES := \
|
|||||||
uninitialized_malloc_usable_size \
|
uninitialized_malloc_usable_size \
|
||||||
eight_byte_overflow_small \
|
eight_byte_overflow_small \
|
||||||
eight_byte_overflow_large \
|
eight_byte_overflow_large \
|
||||||
|
string_overflow
|
||||||
|
|
||||||
all: $(EXECUTABLES)
|
all: $(EXECUTABLES)
|
||||||
|
|
||||||
|
19
test/simple-memory-corruption/string_overflow.c
Normal file
19
test/simple-memory-corruption/string_overflow.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
__attribute__((optimize(0)))
|
||||||
|
int main(void) {
|
||||||
|
char *p = malloc(16);
|
||||||
|
if (!p) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size = malloc_usable_size(p);
|
||||||
|
memset(p, 'a', size);
|
||||||
|
printf("overflow by %zu bytes\n", strlen(p) - size);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user