From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/2] Avoid undefined behavior in gdbscm_make_breakpoint
Date: Mon, 4 Apr 2022 13:51:41 +0100 [thread overview]
Message-ID: <20220404125141.663987-3-pedro@palves.net> (raw)
In-Reply-To: <20220404125141.663987-1-pedro@palves.net>
Running gdb.guile/scm-breakpoint.exp against an --enable-ubsan build,
we see:
UNRESOLVED: gdb.guile/scm-breakpoint.exp: test_watchpoints: create a breakpoint with an invalid type number
...
guile (define wp2 (make-breakpoint "result" #:wp-class WP_WRITE #:type 999))
../../src/gdb/guile/scm-breakpoint.c:377:11: runtime error: load of value 999, which is not a valid value for type 'bptype'
ERROR: GDB process no longer exists
Fix this by parsing the user/guile input as plain int, and cast to
internal type only after we know we have a number that would be valid.
Change-Id: I03578d07db00be01b610a8f5ce72e5521aea6a4b
---
gdb/guile/scm-breakpoint.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index 0069d3371ff..d6c89aa8c71 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -353,8 +353,8 @@ gdbscm_make_breakpoint (SCM location_scm, SCM rest)
char *location;
int type_arg_pos = -1, access_type_arg_pos = -1,
internal_arg_pos = -1, temporary_arg_pos = -1;
- enum bptype type = bp_breakpoint;
- enum target_hw_bp_type access_type = hw_write;
+ int type = bp_breakpoint;
+ int access_type = hw_write;
int internal = 0;
int temporary = 0;
SCM result;
@@ -403,7 +403,7 @@ gdbscm_make_breakpoint (SCM location_scm, SCM rest)
case bp_access_watchpoint:
case bp_catchpoint:
{
- const char *type_name = bpscm_type_to_string (type);
+ const char *type_name = bpscm_type_to_string ((enum bptype) type);
gdbscm_misc_error (FUNC_NAME, type_arg_pos,
gdbscm_scm_from_c_string (type_name),
_("unsupported breakpoint type"));
@@ -417,8 +417,8 @@ gdbscm_make_breakpoint (SCM location_scm, SCM rest)
bp_smob->is_scheme_bkpt = 1;
bp_smob->spec.location = location;
- bp_smob->spec.type = type;
- bp_smob->spec.access_type = access_type;
+ bp_smob->spec.type = (enum bptype) type;
+ bp_smob->spec.access_type = (enum target_hw_bp_type) access_type;
bp_smob->spec.is_internal = internal;
bp_smob->spec.is_temporary = temporary;
--
2.26.2
next prev parent reply other threads:[~2022-04-04 12:51 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 12:51 [PATCH v2 0/2] Fix a couple undefined behaviors flagged by UBSan Pedro Alves
2022-04-04 12:51 ` [PATCH v2 1/2] gdb: Avoid undefined shifts Pedro Alves
2022-04-04 17:21 ` Tom Tromey
2022-04-04 17:54 ` Pedro Alves
2022-04-04 17:59 ` Tom Tromey
2022-04-04 12:51 ` Pedro Alves [this message]
2022-04-04 17:15 ` [PATCH v2 2/2] Avoid undefined behavior in gdbscm_make_breakpoint Tom Tromey
2022-04-04 19:50 ` Pedro Alves
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=20220404125141.663987-3-pedro@palves.net \
--to=pedro@palves.net \
--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).