|
|||||||||||
|
safe mallocs (was Re: vulndev-1 and a suggestion about the ensuing discussion)
From: Bennett Todd <bet(at)rahul.net>
Date: Thu May 15 2003 - 21:49:31 EDT
2003-05-15T12:46:57 xenophi1e:
For immediate detection you need something cleverer; in the worst case, you've gotta enlist the aid of the vm subsystem. But sufficient for this case, and possibly enough to be of some general use, is a strategy I used in an emalloc() wrapper I wrote back in the '80s, part of libbent, dunno if that's still around anywhere, I don't have a copy anymore. It started by my just making a library of things I did so often I could type 'em without having to think, the first was probably
FILE *efopen(char *name, char *mode) {
FILE *ret;
if (ret = fopen(name, mode)) {
return ret;
}
(void) fprintf(stderr, "%s: %s: %s\n", progname, name, strerr(errno));
exit(1);
}
(that may be slightly off, it's been maybe 15 years since I've typed it:-). erealloc and efree checked to make sure the ptrs they were handed had prepended valid canary struct, used the length in it to find and check the trailing one, then freed the "real" malloc pointer to the beginning of the prepended malloc struct. I can't recall it ever actually helping me by catching a bug, but it pleased me at the time. -Bennett
This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:07:39 EDT |
||||||||||
|
|||||||||||