From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by sourceware.org (Postfix) with ESMTPS id A6FA93857C50 for ; Mon, 4 Apr 2022 12:51:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A6FA93857C50 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f43.google.com with SMTP id m30so14381506wrb.1 for ; Mon, 04 Apr 2022 05:51:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CTSbepshf/uLYK0uCCUVwaWzEXiT1NT6d3Wbzg1B/VM=; b=3S3TlCDDZdTDqC+Xl+czAe2o9L8ejfpWPbQiJcZcl6KlW1CFqccUXwgvAPciNGZ6XM MR2ciF86EAtsbnHIy6+2a4ZGiWihPN1cdbgIQN1pjf9CJkqqRZwYGwmbE/KFLgZeL+Xd i7qIGy35RlBNU8l6TFn6UYcP7pYaKo0kqnuPji659IRXZsB1dySx7K0RVTVFUP34lYei n4jSP/m9MUqNjjjB/6Mv5myJ0Z+l/UHMxLabG7Io7qnSX8HLwCjbDELZeVB1FX3yrBPm zazlpzr6h8iHbcSM1nap97a7qhW99NF1z2RmeORdVUlTzlC7Myzh10AAubg9JYUlhzS6 hBbQ== X-Gm-Message-State: AOAM530YpUyGI0J1LugFE7fMvwDgV6F26mUtxLaQzqa0AUeeolsKnRvc m87rLlnRu/FW95qpgICZH98DykI+9e8= X-Google-Smtp-Source: ABdhPJwtjLQByHpgnG7g4cCYWRO5EzNXokxqasMFtIlTa0CCO1rseIPBFtigyqeoaBoDihKa834ejA== X-Received: by 2002:a05:6000:386:b0:203:f8d8:f70 with SMTP id u6-20020a056000038600b00203f8d80f70mr17026305wrf.163.1649076712525; Mon, 04 Apr 2022 05:51:52 -0700 (PDT) Received: from localhost ([2001:8a0:f924:2600:209d:85e2:409e:8726]) by smtp.gmail.com with ESMTPSA id p11-20020a5d638b000000b002048a77636dsm9215684wru.97.2022.04.04.05.51.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 05:51:51 -0700 (PDT) From: Pedro Alves 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 Message-Id: <20220404125141.663987-3-pedro@palves.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220404125141.663987-1-pedro@palves.net> References: <20220404125141.663987-1-pedro@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2022 12:51:56 -0000 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