public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/testsuite: fix buffer overflow in gdb.base/signed-builtin-types.exp
@ 2022-12-24 16:04 Andrew Burgess
  0 siblings, 0 replies; only message in thread
From: Andrew Burgess @ 2022-12-24 16:04 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3a98808c164b36c7023bd80fc6b019cbe6274365

commit 3a98808c164b36c7023bd80fc6b019cbe6274365
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Tue Dec 20 12:51:50 2022 +0000

    gdb/testsuite: fix buffer overflow in gdb.base/signed-builtin-types.exp
    
    In commit:
    
      commit 9f50fe0835850645bd8ea9bb1efe1fe6c48dfb12
      Date:   Wed Dec 7 15:55:25 2022 +0000
    
          gdb/testsuite: new test for recent dwarf reader issue
    
    A new test (gdb.base/signed-builtin-types.exp) was added that made use
    of 'info sources' to figure out if the debug information for a
    particular object file had been fully expanded or not.  Unfortunately
    some lines of the 'info sources' output can be very long, this was
    observed on some systems where the debug information for the
    dynamic-linker was installed, in this case, the list of source files
    associated with the dynamic linker was so long it would cause expect's
    internal buffer to overflow.
    
    This commit switches from using 'info sources' to 'maint print
    objfile', the output from the latter command is more compact, but
    also, can be restricted to a single named object file.
    
    With this change in place I am no longer seeing buffer overflow errors
    from expect when running gdb.base/signed-builtin-types.exp.

Diff:
---
 gdb/testsuite/gdb.base/signed-builtin-types.exp | 51 ++++---------------------
 1 file changed, 8 insertions(+), 43 deletions(-)

diff --git a/gdb/testsuite/gdb.base/signed-builtin-types.exp b/gdb/testsuite/gdb.base/signed-builtin-types.exp
index e9784330fee..30e224fb439 100644
--- a/gdb/testsuite/gdb.base/signed-builtin-types.exp
+++ b/gdb/testsuite/gdb.base/signed-builtin-types.exp
@@ -21,7 +21,8 @@ standard_testfile .c -lib.c
 
 # Compile the shared library.
 set srcdso [file join $srcdir $subdir $srcfile2]
-set objdso [standard_output_file lib${gdb_test_file_name}.so]
+set libname "lib${gdb_test_file_name}.so"
+set objdso [standard_output_file $libname]
 if {[gdb_compile_shlib $srcdso $objdso {debug}] != ""} {
     untested "failed to compile dso"
     return -1
@@ -46,46 +47,10 @@ if {[readnow]} {
 # library has been fully expanded or not.  Return true if the debug
 # information has NOT been fully expanded (which is what we want for this
 # test).
-proc shared_library_debug_not_fully_expanded {} {
-    set library_expanded ""
-    gdb_test_multiple "info sources" "" {
-	-re "^info sources\r\n" {
-	    exp_continue
-	}
-	-re "^(\[^\r\n\]+):\r\n\\(Full debug information has not yet been read for this file\\.\\)\r\n\r\n" {
-	    set libname $expect_out(1,string)
-	    if {$libname == $::objdso} {
-		set library_expanded "no"
-	    }
-	    exp_continue
-	}
-	-re "^(\[^\r\n\]+):\r\n\\(Objfile has no debug information\\.\\)\r\n\r\n" {
-	    set libname $expect_out(1,string)
-	    if {$libname == $::objdso} {
-		# For some reason the shared library has no debug
-		# information, this is not expected.
-		set library_expanded "missing debug"
-	    }
-	    exp_continue
-	}
-	-re "^(\[^\r\n\]+):\r\n\r\n" {
-	    set libname $expect_out(1,string)
-	    if {$libname == $::objdso} {
-		set library_expanded "yes"
-	    }
-	    exp_continue
-	}
-	-re "^$::gdb_prompt $" {
-	    gdb_assert {[string equal $library_expanded "yes"] \
-			    || [string equal $library_expanded "no"]} \
-		$gdb_test_name
-	}
-	-re "^(\[^\r\n:\]*)\r\n" {
-	    exp_continue
-	}
-    }
-
-    return [expr $library_expanded == "no"]
+proc assert_shared_library_debug_not_fully_expanded {} {
+    gdb_test_lines "maint print objfiles $::libname" "" \
+	"Object file \[^\r\n\]*$::libname" \
+	-re-not "Symtabs:"
 }
 
 foreach_with_prefix type_name {"short" "int" "long" "char"} {
@@ -93,7 +58,7 @@ foreach_with_prefix type_name {"short" "int" "long" "char"} {
 	with_test_prefix "before sizeof expression" {
 	    # Check that the debug information for the shared library has
 	    # not yet been read in.
-	    gdb_assert { [shared_library_debug_not_fully_expanded] }
+	    assert_shared_library_debug_not_fully_expanded
 	}
 
 	# Evaluate a sizeof expression for a builtin type.  At one point GDB
@@ -106,7 +71,7 @@ foreach_with_prefix type_name {"short" "int" "long" "char"} {
 	with_test_prefix "after sizeof expression" {
 	    # Check that the debug information for the shared library has not
 	    # yet been read in.
-	    gdb_assert { [shared_library_debug_not_fully_expanded] }
+	    assert_shared_library_debug_not_fully_expanded
 	}
     }
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-24 16:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 16:04 [binutils-gdb] gdb/testsuite: fix buffer overflow in gdb.base/signed-builtin-types.exp Andrew Burgess

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).