add simple string overflow test
parent
b24569b6ca
commit
93fcc6a978
|
@ -20,6 +20,7 @@ EXECUTABLES := \
|
|||
uninitialized_malloc_usable_size \
|
||||
eight_byte_overflow_small \
|
||||
eight_byte_overflow_large \
|
||||
string_overflow
|
||||
|
||||
all: $(EXECUTABLES)
|
||||
|
||||
|
|
|
@ -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