From patchwork Thu Nov 11 15:38:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 47482 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E542A3858017 for ; Thu, 11 Nov 2021 15:39:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id DA5373858408 for ; Thu, 11 Nov 2021 15:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA5373858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C12661FD40; Thu, 11 Nov 2021 15:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1636645127; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lCG0FTBegT4x7/dwZw560WgJMhVmB2XR/lJGA5Vy0F8=; b=d9XY9DS+5+Bi3Lvzjb72yiqB7/zMPoJ2Iog9hvgZTao/dUHLQonsqn3EXDKfO6WJH+b8C6 t1T6DSPuTEKpey+kqnIeIJ0Etu+lSf9/O53Ib7k1TNzIgsRZNyIKUn4ajOtHItq2wXQhkQ o2WImMIqVKPWs1aVLmAnZBqPAbN+r7Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1636645127; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lCG0FTBegT4x7/dwZw560WgJMhVmB2XR/lJGA5Vy0F8=; b=euqFoVAxQaOgeioa7ibcUDLVoA3Yhx2+6z0E17DbsemiYrg+f6ZqbMWWdOMixylta3jJd0 YWtywkZuvh+lr9CQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id AA7E113DBF; Thu, 11 Nov 2021 15:38:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id M4kYKAc5jWH+DwAAMHmgww (envelope-from ); Thu, 11 Nov 2021 15:38:47 +0000 Message-ID: <6e8e9e1c-4c5c-b2c7-9fab-adf3cfd550f3@suse.cz> Date: Thu, 11 Nov 2021 16:38:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] libbacktrace: fix UBSAN issues To: gcc-patches@gcc.gnu.org Content-Language: en-US X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ian Lance Taylor Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin Fix issues mentioned in the PR. PR libbacktrace/103167 libbacktrace/ChangeLog: * elf.c (elf_uncompress_lzma_block): Cast to unsigned int. (elf_uncompress_lzma): Likewise. * xztest.c (test_samples): memcpy only if v > 0. Co-Authored-By: Andrew Pinski --- libbacktrace/elf.c | 8 ++++---- libbacktrace/xztest.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 79d56146fc6..e69ac41c88b 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -3175,7 +3175,7 @@ elf_uncompress_lzma_block (const unsigned char *compressed, stream_crc = (compressed[off] | (compressed[off + 1] << 8) | (compressed[off + 2] << 16) - | (compressed[off + 3] << 24)); + | ((unsigned)(compressed[off + 3]) << 24)); if (unlikely (computed_crc != stream_crc)) { elf_uncompress_failed (); @@ -3788,7 +3788,7 @@ elf_uncompress_lzma (struct backtrace_state *state, stream_crc = (compressed[8] | (compressed[9] << 8) | (compressed[10] << 16) - | (compressed[11] << 24)); + | ((unsigned)(compressed[11]) << 24)); if (unlikely (computed_crc != stream_crc)) { elf_uncompress_failed (); @@ -3832,7 +3832,7 @@ elf_uncompress_lzma (struct backtrace_state *state, stream_crc = (compressed[offset - 4] | (compressed[offset - 3] << 8) | (compressed[offset - 2] << 16) - | (compressed[offset - 1] << 24)); + | ((unsigned)(compressed[offset - 1]) << 24)); if (unlikely (computed_crc != stream_crc)) { elf_uncompress_failed (); @@ -3891,7 +3891,7 @@ elf_uncompress_lzma (struct backtrace_state *state, stream_crc = (compressed[offset] | (compressed[offset + 1] << 8) | (compressed[offset + 2] << 16) - | (compressed[offset + 3] << 24)); + | ((unsigned)(compressed[offset + 3]) << 24)); if (unlikely (computed_crc != stream_crc)) { elf_uncompress_failed (); diff --git a/libbacktrace/xztest.c b/libbacktrace/xztest.c index b2533cb1804..6c60ff50159 100644 --- a/libbacktrace/xztest.c +++ b/libbacktrace/xztest.c @@ -172,7 +172,7 @@ test_samples (struct backtrace_state *state) tests[i].name, uncompressed_len, v); ++failures; } - else if (memcmp (tests[i].uncompressed, uncompressed, v) != 0) + else if (v > 0 && memcmp (tests[i].uncompressed, uncompressed, v) != 0) { size_t j;