From: Andrew STUBBS <andrew.stubbs@st.com>
To: GDB Patches <gdb-patches@sourceware.org>
Subject: command_line_input() not re-entrant
Date: Thu, 30 Mar 2006 14:29:00 -0000 [thread overview]
Message-ID: <442BD6F1.8070804@st.com> (raw)
Hi,
I have discovered a problem in the GDB command line reading code.
command_line_input() uses a static buffer to hold the current command.
This means that it is not properly re-entrant - commands that contain
other commands, such as user defined commands, are not handled safely.
In practice the only real trouble I have observed is with user defined
commands that use $arg0 etc. because these parameters are never copied
out of the original string, so are overwritten the next time
command_line_input() is invoked. Even then, this is not normally a
problem because command_line_input() is not normally needed within a
user-defined command - it has already been read. It is only a problem
when the user defined command contains a source command.
The problem may be reproduced as follows:
Create three files:
a1
---8<---------->8-----
source a2
abcdef qwerty
---8<---------->8-----
a2
---8<---------->8-----
define abcdef
echo 1: <<<$arg0>>>\n
source a3
echo 2: <<<$arg0>>>\n
end
---8<---------->8-----
a3
---8<---------->8-----
#################################################################
---8<---------->8-----
Then run the following command:
$ gdb -nx -q -x a1 -batch
1: <<<qwerty>>>
2: <<<######>>>
Both 1: and 2: should have been the same. As you can see the contents of
a3 have overwritten the value of $arg0 in abcdef. For some reason I
haven't discovered (and probably boils down to dumb luck) I can't
reproduce the problem when entering a1 interactively - I have to source it.
I am happy to write the patch to fix this but I am wondering how. There
seem to be two possible ways:
1. Make command_line_input() re-entrant. Perhaps drop the static buffer
and malloc a new string each time. Free it through a clean-up.
2. Have setup_user_args() copy the data and adjust the clean up to free
the copied data.
Any preferences or other suggestions?
Andrew Stubbs
next reply other threads:[~2006-03-30 13:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-30 14:29 Andrew STUBBS [this message]
2006-04-04 10:27 ` [PATCH] allow nested sourced commands Andrew STUBBS
2006-04-04 10:34 ` Andrew STUBBS
2006-04-04 19:58 ` Michael Snyder
2006-04-05 10:05 ` Andrew STUBBS
2006-04-05 18:48 ` Michael Snyder
2006-04-06 9:49 ` Andrew STUBBS
2006-04-06 13:40 ` Daniel Jacobowitz
2006-04-07 11:17 ` Andrew STUBBS
2006-04-07 13:18 ` Daniel Jacobowitz
2006-04-07 13:33 ` Andrew STUBBS
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=442BD6F1.8070804@st.com \
--to=andrew.stubbs@st.com \
--cc=gdb-patches@sourceware.org \
/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