From: Zhang Zhen <zhenzhang.zhang@huawei.com>
To: <gdb@sourceware.org>
Cc: <xuhanbing@huawei.com>
Subject: The return address of strtok is out of bounds in gdb
Date: Tue, 17 Mar 2015 08:47:00 -0000 [thread overview]
Message-ID: <5507E977.2030003@huawei.com> (raw)
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!
next reply other threads:[~2015-03-17 8:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 8:47 Zhang Zhen [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5507E977.2030003@huawei.com \
--to=zhenzhang.zhang@huawei.com \
--cc=gdb@sourceware.org \
--cc=xuhanbing@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox