aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorSergio Durigan Junior <sergiodj@redhat.com>2018-10-18 12:56:25 -0400
committerSergio Durigan Junior <sergiodj@redhat.com>2018-10-18 17:39:09 -0400
commit94c18618a8e29894a7b3104375e0510d71a568fb (patch)
treeeae691491fb47881c639554d6f1b988dded5ed75 /gdb/cli
parentf63085d15f05eb296744ba634edfc68ca806e578 (diff)
downloadgdb-94c18618a8e29894a7b3104375e0510d71a568fb.zip
gdb-94c18618a8e29894a7b3104375e0510d71a568fb.tar.gz
gdb-94c18618a8e29894a7b3104375e0510d71a568fb.tar.bz2
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.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-dump.c3
1 files changed, 3 insertions, 0 deletions
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)
{