* [PATCH] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"
@ 2018-10-18 17:01 Sergio Durigan Junior
2018-10-18 21:18 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Sergio Durigan Junior @ 2018-10-18 17:01 UTC (permalink / raw)
To: GDB Patches; +Cc: Sergio Durigan Junior
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.
---
gdb/cli/cli-dump.c | 3 +++
gdb/testsuite/gdb.base/restore.exp | 8 ++++++++
2 files changed, 11 insertions(+)
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index e9e393cd55..520c893e0b 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/gdb.base/restore.exp b/gdb/testsuite/gdb.base/restore.exp
index 995dc6e0b2..2aa57f6449 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: .*"
--
2.17.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"
2018-10-18 17:01 [PATCH] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary" Sergio Durigan Junior
@ 2018-10-18 21:18 ` Tom Tromey
2018-10-18 21:40 ` Sergio Durigan Junior
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2018-10-18 21:18 UTC (permalink / raw)
To: Sergio Durigan Junior; +Cc: GDB Patches
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
Sergio> This simple patch fixes the segfault reported on PR cli/23785, which
Sergio> happens when using the "restore FILE binary" command with a
Sergio> non-existent file. We just have to check if the file handler returned
Sergio> by "gdb_fopen_cloexec" is not NULL, and error out if it is.
Sergio> A test has also been added to gdb.base/restore.exp in order to
Sergio> exercise this scenario.
Thanks, this is ok.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary"
2018-10-18 21:18 ` Tom Tromey
@ 2018-10-18 21:40 ` Sergio Durigan Junior
0 siblings, 0 replies; 3+ messages in thread
From: Sergio Durigan Junior @ 2018-10-18 21:40 UTC (permalink / raw)
To: Tom Tromey; +Cc: GDB Patches
On Thursday, October 18 2018, Tom Tromey wrote:
>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio> This simple patch fixes the segfault reported on PR cli/23785, which
> Sergio> happens when using the "restore FILE binary" command with a
> Sergio> non-existent file. We just have to check if the file handler returned
> Sergio> by "gdb_fopen_cloexec" is not NULL, and error out if it is.
>
> Sergio> A test has also been added to gdb.base/restore.exp in order to
> Sergio> exercise this scenario.
>
> Thanks, this is ok.
Thanks, pushed.
94c18618a8e29894a7b3104375e0510d71a568fb
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-10-18 21:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-18 17:01 [PATCH] Fix PR cli/23785: Check if file exists when invoking "restore FILE binary" Sergio Durigan Junior
2018-10-18 21:18 ` Tom Tromey
2018-10-18 21:40 ` Sergio Durigan Junior
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).