From patchwork Thu Aug 3 13:26:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 130584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1147430vqx; Thu, 3 Aug 2023 06:27:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlEycEKtAeT82sNpPiuLzFfluiYlHu315XZK5csNln60GkVpLQDfn5AMYGVwo1hMZIQ3jA+i X-Received: by 2002:a17:907:762d:b0:99b:574f:d201 with SMTP id jy13-20020a170907762d00b0099b574fd201mr8246744ejc.40.1691069236899; Thu, 03 Aug 2023 06:27:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691069236; cv=none; d=google.com; s=arc-20160816; b=OCU6bYP3IRVkAbSb/xeYMP74AXKLNaLbzgBPF17KRjt3EBi1bT5YoT/ZWM5MACNmgC l+gA/8Ysu5vIaV16pCxWLGMSJMqmG0RKv2kCyb1e30PUtGIrUUKEcllfpDs1/4YpaJha m5heKyB02eHMwkazbFUsOyZFwsTfFTG/+qrZEk0VS74BUuOPs5iuIQJpTXgIiYPAKb41 9VGx0QQP7ldTl52OCtQ6kJF21IcprUEhIwIv+o4+/8Iyfm7L4FU07x5PNWxk1QOOg4rW 7jfsTO5bv2kDaTEE5gygHrbVJ2Wl4hkgq1/3/cFnMVExhOcOTsJwlVxM2L00ZnJ9MEug MVkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=5hFJGn2zcaqXD/d8jHy+rUfm0XSYY9rvlI1CR1W+cDs=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=ozxSLJUEWYCKWcqgCJ/j4KS5f0uS28oncWYoFpVdpLlTuWiLYUD3zmGE1iPKyil6Ho bjWrnXMS94wfqQU+rRPn9nqHXBhrKoNzCl6CT1Z/V7GwwzjvuvQON1pZ8SUU8OlxZer3 RNfMO/BJy3WGQldmb+maC1g6yJ2AejIDUzQQTLAhTeKG/nIAazxq37iCMU8/cr3oiypu uohGfaWS8to8M/rYgnUTkojy3QQQF8UzuGSdPYAM6MDCcb65z1OjUv629bSVmRPFXrFE XOMnz5HEmc9iOWYLQA3t0sdWW0FUgEGrQ0BLGt8R2T+hj+B53y8qu181eLSUSvxzeVlo F3kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bUoN9By6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lu22-20020a170906fad600b0099bc91d70cdsi456307ejb.545.2023.08.03.06.27.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 06:27:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bUoN9By6; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 000023858D35 for ; Thu, 3 Aug 2023 13:27:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 000023858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691069235; bh=5hFJGn2zcaqXD/d8jHy+rUfm0XSYY9rvlI1CR1W+cDs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bUoN9By6Y5ntGrdLogShxLdjcj51uIg/8ttAd5e9p/piouAz+smEkpPaT+caRKQDT MrbrWQrJc3g665gL5AjPJ8lkc4elAr9pHfDCoZjOWRPGio0S2GN3aMhnhhu9Lzoy8z ochqeFoQnOD23EKKWqRnXDf05owfgzTluxN5uPv0= 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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 163E03858D1E for ; Thu, 3 Aug 2023 13:26:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 163E03858D1E Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id F14461F749 for ; Thu, 3 Aug 2023 13:26:29 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id E6C4D2C142 for ; Thu, 3 Aug 2023 13:26:29 +0000 (UTC) Date: Thu, 3 Aug 2023 13:26:29 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] [libbacktrace] fix up broken test User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230803132715.000023858D35@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773214615992629029 X-GMAIL-MSGID: 1773214615992629029 zstdtest has some inline data where some testcases lack the uncompressed length field. Thus it computes that but still ends up allocating memory for the uncompressed buffer based on that (zero) length. Oops. Causes memory corruption if the allocator returns non-NULL. Tested on x86_64-unknown-linux-gnu, pushed as obvious. libbacktrace/ * zstdtest.c (test_samples): Properly compute the allocation size for the uncompressed data. --- libbacktrace/zstdtest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libbacktrace/zstdtest.c b/libbacktrace/zstdtest.c index 1b4158a50eb..1a27d90e29e 100644 --- a/libbacktrace/zstdtest.c +++ b/libbacktrace/zstdtest.c @@ -197,7 +197,11 @@ test_samples (struct backtrace_state *state) unsigned char *uncompressed; size_t uncompressed_len; - uncompressed = (unsigned char *) malloc (tests[i].uncompressed_len); + uncompressed_len = tests[i].uncompressed_len; + if (uncompressed_len == 0) + uncompressed_len = strlen (tests[i].uncompressed); + + uncompressed = (unsigned char *) malloc (uncompressed_len); if (uncompressed == NULL) { perror ("malloc"); @@ -206,10 +210,6 @@ test_samples (struct backtrace_state *state) continue; } - uncompressed_len = tests[i].uncompressed_len; - if (uncompressed_len == 0) - uncompressed_len = strlen (tests[i].uncompressed); - if (!backtrace_uncompress_zstd (state, ((const unsigned char *) tests[i].compressed),