This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"


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

commit 94c18618a8e29894a7b3104375e0510d71a568fb
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Thu Oct 18 12:56:25 2018 -0400

    Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"
    
    This simple patch fixes the segfault reported on PR cli/23785, which
    happens when using the "restore FILE binary" command with a
    non-existent file.  We just have to check if the file handler returned
    by "gdb_fopen_cloexec" is not NULL, and error out if it is.
    
    A test has also been added to gdb.base/restore.exp in order to
    exercise this scenario.
    
    No regressions introduced.
    
    gdb/ChangeLog:
    2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>
    
    	PR cli/23785
    	* cli/cli-dump.c (restore_binary_file): Check if "file" is
    	NULL.
    
    gdb/testsuite/ChangeLog:
    2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>
    
    	PR cli/23785
    	* gdb.base/restore.exp: New test to check if "restore" with an
    	invalid file doesn't segfault.

Diff:
---
 gdb/ChangeLog                      | 6 ++++++
 gdb/cli/cli-dump.c                 | 3 +++
 gdb/testsuite/ChangeLog            | 6 ++++++
 gdb/testsuite/gdb.base/restore.exp | 8 ++++++++
 4 files changed, 23 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 81ac022..e177cf2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	PR cli/23785
+	* cli/cli-dump.c (restore_binary_file): Check if "file" is
+	NULL.
+
 2018-10-17  Paul Koning  <paul_koning@dell.com>
 
 	* charset.c (convert_between_encodings): Fix unsigned overflow.
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index e9e393c..520c893 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -468,6 +468,9 @@ restore_binary_file (const char *filename, struct callback_data *data)
   gdb_file_up file = gdb_fopen_cloexec (filename, FOPEN_RB);
   long len;
 
+  if (file == NULL)
+    error (_("Failed to open %s: %s"), filename, safe_strerror (errno));
+
   /* Get the file size for reading.  */
   if (fseek (file.get (), 0, SEEK_END) == 0)
     {
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8fa224a..a7bd87d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-10-18  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+	PR cli/23785
+	* gdb.base/restore.exp: New test to check if "restore" with an
+	invalid file doesn't segfault.
+
 2018-10-18  Tom de Vries  <tdevries@suse.de>
 
 	* gdb.ada/bp_inlined_func.exp: Fix capitalized test name.
diff --git a/gdb/testsuite/gdb.base/restore.exp b/gdb/testsuite/gdb.base/restore.exp
index 995dc6e..2aa57f6 100644
--- a/gdb/testsuite/gdb.base/restore.exp
+++ b/gdb/testsuite/gdb.base/restore.exp
@@ -86,3 +86,11 @@ set prev_timeout $timeout
 set timeout 30
 restore_tests
 set timeout $prev_timeout
+
+# Test PR cli/23785
+clean_restart $binfile
+if { ![runto_main] } {
+    return -1
+}
+gdb_test "restore non-existent-file binary" \
+    "Failed to open non-existent-file: .*"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]