public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb: fix off-by-one error in quirk_rust_enum
@ 2020-05-19 18:20 Simon Marchi
0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2020-05-19 18:20 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f408d82c7a140268c3b7be35970c96d8385b5902
commit f408d82c7a140268c3b7be35970c96d8385b5902
Author: Simon Marchi <simon.marchi@efficios.com>
Date: Tue May 19 14:20:23 2020 -0400
gdb: fix off-by-one error in quirk_rust_enum
Found by inspection, so I don't have a test for it (I don't think it
would be easy to have this bug cause a failure reliably).
We allocate space for N fields into `new_fields`, then memcpy N fields
at `new_fields + 1`. This overflows the allocated buffer by one field.
Fix it by allocating `N + 1` fields.
gdb/ChangeLog:
* dwarf2/read.c (quirk_rust_enum): Allocate enough fields.
Diff:
---
gdb/ChangeLog | 4 ++++
gdb/dwarf2/read.c | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f62557da6c0..ac0beef5ad5 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2020-05-19 Simon Marchi <simon.marchi@efficios.com>
+
+ * dwarf2/read.c (quirk_rust_enum): Allocate enough fields.
+
2020-05-19 Pedro Alves <palves@redhat.com>
* NEWS (set exec-file-mismatch): Adjust entry.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 0c6182bbf3b..2ab7c5c3313 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9420,7 +9420,7 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
/* Make space for the discriminant field. */
struct field *disr_field = &TYPE_FIELD (disr_type, 0);
field *new_fields
- = (struct field *) TYPE_ZALLOC (type, (TYPE_NFIELDS (type)
+ = (struct field *) TYPE_ZALLOC (type, ((TYPE_NFIELDS (type) + 1)
* sizeof (struct field)));
memcpy (new_fields + 1, TYPE_FIELDS (type),
TYPE_NFIELDS (type) * sizeof (struct field));
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-05-19 18:20 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 18:20 [binutils-gdb] gdb: fix off-by-one error in quirk_rust_enum Simon Marchi
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).