From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 562CE3858426 for ; Fri, 20 Jan 2023 16:51:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 562CE3858426 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 89D001E0D3; Fri, 20 Jan 2023 11:51:30 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1674233490; bh=O36+5qnH+NdbD1jugO9y+SShNTBi381q34KiPfY/yOU=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=f8AUZJHMC6rq7x6Yc2zgHp0hSfUB3BbGT9lGidnwSorQtoLiyW7+AzCooDoHzjGau IaaJQVOAUDvRY8+0QvMMeRQe/pWWtUfoX79yqU0iiqf93yi+Vx/hzOidlMUPmYqQYS 3QNwCzbM5TvlaxCrT17q8gZAghbZNT6cqBzIiDNM= Message-ID: <92b91e11-10bc-ff5a-1bde-901ae8e3388f@simark.ca> Date: Fri, 20 Jan 2023 11:51:29 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH 2/2] gdb/dwarf: fix UBsan crash in read_subrange_type Content-Language: en-US To: Andrew Burgess , Simon Marchi via Gdb-patches Cc: Simon Marchi References: <20230120050824.306976-1-simon.marchi@efficios.com> <20230120050824.306976-2-simon.marchi@efficios.com> <87fsc5e4tu.fsf@redhat.com> From: Simon Marchi In-Reply-To: <87fsc5e4tu.fsf@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >> @@ -17684,15 +17683,25 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) >> with GCC, for instance, where the ambiguous DW_FORM_dataN form >> is used instead. To work around that ambiguity, we treat >> the bounds as signed, and thus sign-extend their values, when >> - the base type is signed. */ >> - negative_mask = >> - -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1)); >> - if (low.kind () == PROP_CONST >> - && !base_type->is_unsigned () && (low.const_val () & negative_mask)) >> - low.set_const_val (low.const_val () | negative_mask); >> - if (high.kind () == PROP_CONST >> - && !base_type->is_unsigned () && (high.const_val () & negative_mask)) >> - high.set_const_val (high.const_val () | negative_mask); >> + the base type is signed. >> + >> + Skip it if the base type's length is largest than ULONGEST, to avoid > > s/largest/larger/ Fixed. >> @@ -92,3 +112,5 @@ gdb_test "ptype TByteArray" \ >> "type = array \\\[0\\.\\.191\\\] of byte" >> gdb_test "ptype subrange_with_buggy_negative_bounds_variable" \ >> "type = -16..-12" >> +gdb_test "ptype a_16_byte_subrange_variable" \ >> + "type = -9223372036854775808..9223372036854775807" > > As before, I'd use "\\.\\." here. Fixed. > Looks good with those nits fixed. Thanks, will push. Simon