From: Luis Machado <luis.machado@linaro.org>
To: gdb-patches@sourceware.org
Subject: [PATCH] Fix malloc allocation size sanity check
Date: Wed, 12 Aug 2020 16:17:41 -0300 [thread overview]
Message-ID: <20200812191741.4220-1-luis.machado@linaro.org> (raw)
During debugging of PR26362, it was noticed that the malloc size check
in check_type_length_before_alloc wasn't detecting an allocation attempt
of a huge amount of bytes, making GDB run into an internal error.
This happens because we're using an int to store a type's length. When the
type length is large enough, the int will overflow and the max_value_size
check won't work anymore.
The following patch fixes this by making the length variable a size_t.
Printing statements were also updated to show the correct number of bytes.
gdb/ChangeLog:
YYYY-MM-DD Luis Machado <luis.machado@linaro.org>
* value.c (check_type_length_before_alloc): Use size_t to store a
type's length.
Use %s and pulongest to print the length.
---
gdb/value.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/gdb/value.c b/gdb/value.c
index aac9baaaf5..4efd75fa25 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -997,16 +997,16 @@ show_max_value_size (struct ui_file *file, int from_tty,
static void
check_type_length_before_alloc (const struct type *type)
{
- unsigned int length = TYPE_LENGTH (type);
+ size_t length = TYPE_LENGTH (type);
if (max_value_size > -1 && length > max_value_size)
{
if (type->name () != NULL)
- error (_("value of type `%s' requires %u bytes, which is more "
- "than max-value-size"), type->name (), length);
+ error (_("value of type `%s' requires %s bytes, which is more "
+ "than max-value-size"), type->name (), pulongest (length));
else
- error (_("value requires %u bytes, which is more than "
- "max-value-size"), length);
+ error (_("value requires %s bytes, which is more than "
+ "max-value-size"), pulongest (length));
}
}
--
2.17.1
next reply other threads:[~2020-08-12 19:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 19:17 Luis Machado [this message]
2020-08-12 19:31 ` Tom Tromey
2020-08-12 19:32 ` Tom Tromey
2020-08-12 19:46 ` Luis Machado
2020-08-17 11:01 ` Gary Benson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200812191741.4220-1-luis.machado@linaro.org \
--to=luis.machado@linaro.org \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox