Re: gdb not catching out-of-bounds pointer
- From: Nate Eldredge <nate@xxxxxxxxxx>
- Date: Thu, 11 Dec 2008 09:06:58 -0800
Tomás Ó hÉilidhe <toe@xxxxxxxxxxx> writes:
Here's my program:
#include <string.h>
int main(void)
{
char buf1[5];
char buf2[5]; /* Only got room for a 4-character string */
strcpy(buf2, "dogs5"); /* Wups the source string is too long */
return 0;
}
I don't get a segfault because buf2 spills over into buf1. Ideally I
would like gdb to catch the out-of-bounds error, but instead it runs
it without error:
(gdb) run
Starting program: /home/toe/blah
Program exited normally.
(gdb)
Is there anyway I can set gdb to catch this kind of error?
If you know what array is being overrun, and you just want to know
where, you might be able to set a watchpoint at the address one byte
past the end of the array.
Otherwise, you need something like valgrind, which effectively
single-steps your program and does bounds checking. It will be
dramatically slower than running the program normally, and isn't
supported on all platfoms.
Unfortunately, this is something that C tools have a hard time dealing
with, other than to tell the programmer "Be more careful."
.
- Follow-Ups:
- Re: gdb not catching out-of-bounds pointer
- From: Tomás Ó hÉilidhe
- Re: gdb not catching out-of-bounds pointer
- References:
- gdb not catching out-of-bounds pointer
- From: Tomás Ó hÉilidhe
- gdb not catching out-of-bounds pointer
- Prev by Date: Re: TCP Server does not recv() anything
- Next by Date: Re: perror() a standard ?
- Previous by thread: Re: gdb not catching out-of-bounds pointer
- Next by thread: Re: gdb not catching out-of-bounds pointer
- Index(es):
Relevant Pages
|