From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>,
simark@simark.ca, Simon Marchi <simon.marchi@efficios.com>
Subject: [pushed] gdb/testsuite: add test for Python commands redefining itself
Date: Fri, 16 Dec 2022 11:39:30 +0000 [thread overview]
Message-ID: <20221216113930.80695-1-jan.vrany@labware.com> (raw)
This commit adds a test that creates a Python command that redefines
itself during its execution. This is to test use-after-free in
execute_command ().
This test needs run with ASan enabled in order to fail when it
should.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
gdb/testsuite/gdb.python/py-cmd.exp | 30 +++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/gdb/testsuite/gdb.python/py-cmd.exp b/gdb/testsuite/gdb.python/py-cmd.exp
index aa95a459f46..48c3e18f1cc 100644
--- a/gdb/testsuite/gdb.python/py-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-cmd.exp
@@ -300,3 +300,33 @@ gdb_test_multiple "test_multiline" $test {
pass $test
}
}
+
+# Test command redefining itself
+
+proc_with_prefix test_command_redefining_itself {} {
+ # Start with a fresh gdb
+ clean_restart
+
+
+ gdb_test_multiline "input command redefining itself" \
+ "python" "" \
+ "class redefine_cmd (gdb.Command):" "" \
+ " def __init__ (self, msg):" "" \
+ " super (redefine_cmd, self).__init__ (\"redefine_cmd\", gdb.COMMAND_OBSCURE)" "" \
+ " self._msg = msg" "" \
+ " def invoke (self, arg, from_tty):" "" \
+ " print (\"redefine_cmd output, msg = %s\" % self._msg)" "" \
+ " redefine_cmd (arg)" "" \
+ "redefine_cmd (\"XXX\")" "" \
+ "end" ""
+
+ gdb_test "redefine_cmd AAA" \
+ "redefine_cmd output, msg = XXX" \
+ "call command redefining itself 1"
+
+ gdb_test "redefine_cmd BBB" \
+ "redefine_cmd output, msg = AAA" \
+ "call command redefining itself 2"
+}
+
+test_command_redefining_itself
--
2.35.1
reply other threads:[~2022-12-16 11:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221216113930.80695-1-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).