[PATCH] [PR corefiles/17808] i386: Fix internal error when prstatus in core file is too big

Andreas Arnez
2015-01-08T16:16:28Z

As reported in PR 17808, a test case with a forged (invalid) core file
can crash GDB with an assertion failure. In that particular case the
prstatus of an i386 core file looks like that from an AMD64 core file,
i.e., it is larger than GDB would expect.

The patch replaces the assertion by a warning and skips the invalid
core file register section. In this way it is guaranteed that no
bogus register values are read from the badly formatted section.

Note that this behavior deviates from the default policy: In general, if
some future kernel adds new registers to a register set, then a GDB
unaware of this extension would read the known subset and just ignore
the unknown bytes.

gdb/ChangeLog:

PR corefiles/17808
* i386-tdep.c (i386_supply_gregset): Instead of yielding an
internal error on unexpected input buffer size, ignore the data
and emit a warning.

---
gdb/i386-tdep.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 7d174c4..d02aaf2 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -3727,7 +3727,12 @@ i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
const gdb_byte *regs = gregs;
int i;

- gdb_assert (len == tdep->sizeof_gregset);
+ if (len != tdep->sizeof_gregset)
+ {
+ /* Buffer has unknown size: assume wrong format. */
+ warning (_("Bad size of general register section"));
+ return;
+ }

for (i = 0; i < tdep->gregset_num_regs; i++)
{
--
1.7.9.5