This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] testsuite: Avoid a buffer overrun in `gdb.base/maint.exp'
- From: Pedro Alves <palves at redhat dot com>
- To: "Maciej W. Rozycki" <macro at imgtec dot com>, gdb-patches at sourceware dot org
- Date: Fri, 28 Oct 2016 12:49:25 +0100
- Subject: Re: [PATCH] testsuite: Avoid a buffer overrun in `gdb.base/maint.exp'
- Authentication-results: sourceware.org; auth=none
- References: <alpine.DEB.2.00.1610191938330.31859@tp.orcam.me.uk>
On 10/19/2016 08:07 PM, Maciej W. Rozycki wrote:
> I've looked into adjusting the size of the buffer dynamically as the
> `full_buffer' condition triggers and in principle it appears doable with
> the tools TCL and `expect' provide and no need to bend backwards to get it
> done, however it seems to require more than just a trivial intervention in
> `gdb_test_multiple', so I have decided to leave it for the next time the
> issue triggers. Maybe it won't.
>
> Needless to say, this change has passed `mips-mti-linux-gnu' regression
> testing. OK to apply?
I saw this too yesterday after fixing:
https://sourceware.org/ml/gdb-patches/2016-10/msg00786.html
but came up with a different fix. This one does not require growing
the buffer dynamically. We instead parse output as is comes, with
exp_continue, which should fix the problem for good.
WDYT?
>From d4ac077aa309cc3816ad0dd0cc9c0ef2d91cd7fc Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 28 Oct 2016 12:03:18 +0100
Subject: [PATCH] gdb/testsuite: Avoid a buffer overrun in `gdb.base/maint.exp'
Fixes:
PASS: gdb.base/maint.exp: maint w/o args
ERROR: internal buffer is full.
UNRESOLVED: gdb.base/maint.exp: maint info line-table w/o a file name
The problem is just many symtabs and long line tables, enough to
overflow the expect buffer. Fix this by matching input incrementally.
gdb/testsuite/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
* gdb.base/maint.exp <maint info line-table w/o a file name>: Use
gdb_test_multiple, tighten regexps and match symtabs and line
tables incrementally.
---
gdb/testsuite/gdb.base/maint.exp | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index e66f566..b07b370 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -474,9 +474,41 @@ gdb_test "maint" \
"\"maintenance\" must be followed by the name of a maintenance command\\.\r\nList.*unambiguous\\..*" \
"maint w/o args"
-gdb_test "maint info line-table" \
- "symtab: \[^\n\r\]+${srcfile}.*\\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX.*LINE.*ADDRESS.*" \
- "maint info line-table w/o a file name"
+# Test that "main info line-table" w/o a file name shows the symtab for
+# $srcfile.
+set saw_srcfile 0
+set test "maint info line-table w/o a file name"
+gdb_test_multiple "maint info line-table" $test {
+ -re "symtab: \[^\n\r\]+${srcfile} \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS" {
+ set saw_srcfile 1
+ exp_continue
+ }
+ -re "symtab: \[^\n\r\]+ \\(\\(struct symtab \\*\\) $hex\\)\r\nlinetable: \\(\\(struct linetable \\*\\) $hex\\):\r\nINDEX\[ \t\]+LINE\[ \t\]+ADDRESS" {
+ # Match each symtab to avoid overflowing expect's buffer.
+ exp_continue
+ }
+ -re "$decimal\[ \t\]+$decimal\[ \t\]+$hex\r\n" {
+ # Line table entries can be long too:
+ #
+ # INDEX LINE ADDRESS
+ # 0 29 0x00000000004006f6
+ # 1 30 0x00000000004006fa
+ # 2 31 0x0000000000400704
+ # 3 42 0x0000000000400706
+ # 4 43 0x0000000000400719
+ # 5 44 0x0000000000400722
+ # 6 45 0x0000000000400740
+ # (...)
+ # 454 129 0x00007ffff7df1d28
+ # 455 0 0x00007ffff7df1d3f
+ #
+ # Match each line to avoid overflowing expect's buffer.
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ gdb_assert $saw_srcfile $test
+ }
+}
gdb_test "maint info line-table ${srcfile}" \
"symtab: \[^\n\r\]+${srcfile}.*INDEX.*LINE.*ADDRESS.*" \
--
2.5.5