Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* The return address of strtok is out of bounds in gdb
@ 2015-03-17  8:47 Zhang Zhen
  2015-03-17 11:06 ` Yao Qi
  0 siblings, 1 reply; 5+ messages in thread
From: Zhang Zhen @ 2015-03-17  8:47 UTC (permalink / raw)
  To: gdb; +Cc: xuhanbing

Hi,

I found a problem with gdb-7.9 on my x86_64 machine.
The return address is out of bounds by calling call strtok in gdb.
But if we enter 'n', the return address is correct.
I want to know this is a bug ? If so, how to resolve it ?

It is easily reproduced as follows:

	Fs-Server:/opt/zhangzhen/gdb-7.9 # ./gdb/gdb -q ../strtok_test
	Reading symbols from ../strtok_test...done.
	(gdb) b 12
	Breakpoint 1 at 0x4005c7: file strtok_test.c, line 12.
	(gdb) r
	Starting program: /opt/zhangzhen/strtok_test

	Breakpoint 1, main (argc=1, argv=0x7fffffffe358) at strtok_test.c:12
	12		p1 = strtok(a0, se);
	(gdb) p p1
	$1 = 0x0
	(gdb) p p1 = strtok(a0, se)
	$2 = 0xffffffffffffe260 <error: Cannot access memory at address 0xffffffffffffe260>
	(gdb) n
	13		printf("a0=%s\np1=%p\n", a0, p1);
	(gdb) p p1
	$3 = 0x7fffffffe260 "start"
	(gdb)

The source code of strtok_test is:
	  1 #include <stdio.h>
	  2 #include <stdlib.h>
	  3 #include <string.h>
	  4
	  5 int main(int argc, const char **argv)
	  6 {
	  7         char a0[] = {"start test! "};
	  8
	  9         char *p1 = NULL;
	 10         char se[] = " ";
	 11
	 12         p1 = strtok(a0, se);
	 13         printf("a0=%s\np1=%p\n", a0, p1);
	 14
	 15         return 0;
	 16 }


Best regards!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-19 15:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-17  8:47 The return address of strtok is out of bounds in gdb Zhang Zhen
2015-03-17 11:06 ` Yao Qi
2015-03-17 11:26   ` Andreas Schwab
2015-03-18  3:09     ` Zhang Zhen
2015-03-19 15:15       ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox