From f7d562be536bca329065acdde5a3fcfc0d123d07 Mon Sep 17 00:00:00 2001 From: Igmar Palsenberg Date: Mon, 6 Jun 2011 16:53:13 +0200 Subject: [PATCH 3/6] Use raise(SIGSEGV) instead of the nasty NULL pointer dereference --- src/malloc/malloc.c | 6 ++++-- src/time/__asctime.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 79db0fa..fda7004 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -395,7 +395,8 @@ void *realloc(void *p, size_t n) size_t oldlen = n0 + extra; size_t newlen = n + extra; /* Crash on realloc of freed chunk */ - if ((uintptr_t)base < mal.brk) *(char *)0=0; + if ((uintptr_t)base < mal.brk) + raise(SIGSEGV); if (newlen < PAGE_SIZE && (new = malloc(n))) { memcpy(new, p, n-OVERHEAD); free(p); @@ -458,7 +459,8 @@ void free(void *p) char *base = (char *)self - extra; size_t len = CHUNK_SIZE(self) + extra; /* Crash on double free */ - if ((uintptr_t)base < mal.brk) *(char *)0=0; + if ((uintptr_t)base < mal.brk) + raise(SIGSEGV); __munmap(base, len); return; } diff --git a/src/time/__asctime.c b/src/time/__asctime.c index 1853580..fc4d61d 100644 --- a/src/time/__asctime.c +++ b/src/time/__asctime.c @@ -1,5 +1,6 @@ #include #include +#include #include const char *__langinfo(nl_item); @@ -21,7 +22,7 @@ char *__asctime(const struct tm *tm, char *buf) * application developers that they may not be so lucky * on other implementations (e.g. stack smashing..). */ - *(int*)0 = 0; + raise(SIGSEGV); } return buf; } -- 1.7.5.2