From: Peter H S. <smi...@us...> - 2003-03-28 18:43:26
|
When I run a program under valgrind, pthread_self() will return a number between 1 and 50. This doesn't catch some latent errors. Consider this simplification of some bone-headed trace code: #define PENNY_WISE 5 char header[PENNY_WISE]; sprintf(header, "%d: ", pthread_self()); fprintf(stderr, "%s%s\n", header, message); There is a latent buffer overrun here that won't be tripped under Valgrind because thread ids are always small. I'd like to be able to set the base thread id to something like 0x800000000 or 0xFFFF0000 and test to be sure this buffer nonsense is not a problem. I suppose it's harder, but it would also be nice to be able to put a "translation layer" between getpid() and kill(), etc so that you could force pids to be large too. At least make getpid() return a configurable value like 0x80000000 or 0xF0000000, and have kill() turn it back to the right value before passing it on. Ideally translate any returned pid to have some minimum value, and translate the returned pids to real pids on the way out. This wouldn't be perfect but would be useful in stoopid programs. I suppose I should get over "code approach anxiety" and add it myself, but I'm too busy finding bone-headed buffer overflows to put it in right now... Peter H. Smith Advisory Software Engineer xSeries Systems Management IBM Server Group Phone (919) 543-6140 (T/L 441-6140) email: smi...@us... |