From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 08/10] Avoid undefined behavior in ada_operator_length
Date: Thu, 30 Aug 2018 02:44:00 -0000 [thread overview]
Message-ID: <20180830024416.23386-9-tom@tromey.com> (raw)
In-Reply-To: <20180830024416.23386-1-tom@tromey.com>
-fsanitize=undefined pointed out this error:
runtime error: load of value 2887952, which is not a valid value for type 'exp_opcode'
This happens in gdb.ada/complete.exp when processing "complete p
my_glob". This does not parse, so the Ada parser throws an exception;
but then the code in parse_exp_in_context_1 accepts the expression
anyway. However, as no elements have been written to the expression,
undefined behavior results.
The fix is to notice this case in parse_exp_in_context_1. This patch
also adds an assertion to prefixify_expression to enforce this
pre-existing constraint.
gdb/ChangeLog
2018-08-29 Tom Tromey <tom@tromey.com>
* parse.c (prefixify_expression): Add assert.
(parse_exp_in_context_1): Throw exception if the expression is
empty.
---
gdb/ChangeLog | 8 +++++++-
gdb/parse.c | 6 +++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/gdb/parse.c b/gdb/parse.c
index 163852cb84c..8a128a74d77 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -792,6 +792,7 @@ copy_name (struct stoken token)
int
prefixify_expression (struct expression *expr)
{
+ gdb_assert (expr->nelts > 0);
int len = sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts);
struct expression *temp;
int inpos = expr->nelts, outpos = 0;
@@ -1205,7 +1206,10 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
}
CATCH (except, RETURN_MASK_ALL)
{
- if (! parse_completion)
+ /* If parsing for completion, allow this to succeed; but if no
+ expression elements have been written, then there's nothing
+ to do, so fail. */
+ if (! parse_completion || ps.expout_ptr == 0)
throw_exception (except);
}
END_CATCH
--
2.13.6
next prev parent reply other threads:[~2018-08-30 2:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-30 2:44 [PATCH v2 00/10] Enable undefined behavior sanitizer Tom Tromey
2018-08-30 2:44 ` [PATCH v2 02/10] Change dwarf2_frame_state_reg_info::reg to be std::vector Tom Tromey
2018-08-30 2:44 ` [PATCH v2 04/10] Avoid undefined behavior in extract_integer Tom Tromey
2018-08-30 2:44 ` [PATCH v2 01/10] Do not pass NULL to memcpy Tom Tromey
2018-08-30 2:44 ` [PATCH v2 05/10] Avoid undefined behavior in read_subrange_type Tom Tromey
2018-08-30 2:44 ` [PATCH v2 07/10] Avoid undefined behavior in read_signed_leb128 Tom Tromey
2018-08-30 2:44 ` [PATCH v2 03/10] Use unsigned as base type for some enums Tom Tromey
2018-08-30 2:44 ` Tom Tromey [this message]
2018-08-30 2:44 ` [PATCH v2 09/10] Avoid undefined behavior in expression dumping Tom Tromey
2018-08-30 2:44 ` [PATCH v2 06/10] Avoid undefined behavior in parse_number Tom Tromey
2018-08-30 2:44 ` [PATCH v2 10/10] Add --enable-ubsan Tom Tromey
2018-09-12 11:49 ` [PATCH v2 00/10] Enable undefined behavior sanitizer Tom Tromey
2018-10-02 4:44 [PATCH v2 00/10] Undefined Behavior Sanitizer, this time with docs Tom Tromey
2018-10-02 4:44 ` [PATCH v2 08/10] Avoid undefined behavior in ada_operator_length Tom Tromey
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=20180830024416.23386-9-tom@tromey.com \
--to=tom@tromey.com \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).