From patchwork Wed Apr 12 01:34:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 82226 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2975430vqo; Tue, 11 Apr 2023 18:34:22 -0700 (PDT) X-Google-Smtp-Source: AKy350aRa3g7/jWKD49yo1Y3WdJgLqu+W6jDUYHRNBcZcZDviWaEiG55qG9xl3k6ZuUll1F/cQrU X-Received: by 2002:a05:6402:10d1:b0:505:47a:7ae9 with SMTP id p17-20020a05640210d100b00505047a7ae9mr351333edu.8.1681263262645; Tue, 11 Apr 2023 18:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681263262; cv=none; d=google.com; s=arc-20160816; b=Ly/D0CEG77AYsUne7gt4SrErsxCfVBpcnMmPfx4+aEde0BWRIvpQINgk72lTzWdyTN gj7VMP/6yxiuTvVn7getyADJ8iCtkiQcJJewzEbVy7XMFeIS6vCvBpDlWEKEMY/cui06 gKgahF/0jkqKYAJo+pfXta3MP+9Lbc5dUGFsWeACGBUUhs+sVDf21ayVSeV9vqszWRgk huEWmR7D5ZcZktrVdoDBXT4CAc+iACq7555NdIn1pgCOCSfLEqHmuQ4HVoVvqnR6XQ1i AY4JTZTcCwuuYXvIB7h9B2sCOpT2WM+z0nV0VOjNM3zUYMMPeUC5sMx74aNPulTOZbRy NAdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=iAtRJ38xL5e+z5pZG3Dze3j0v+lX5XfAdyE/BRi1ZBg=; b=uJ53AC4S7507+z4SAfQSpuyNNHsVCgz73PMkWqJFyuvEhPvHEAPk/+HH0XK4gzOdfB jrsXeW7yN35rKWDqny8GogI2ZxOaRmyxJjTLjsuknNO1wjxzMnzp0hjzpevJued+UR0P NLcjrdzkJKKEOemtkZuEuMC0xAp/Q3H432am7qu4qQQa8pELD+mKITZzpIu49ipY1+HA 5LMaDrrj/uaUy3/a+MASWAw34FNguzETVLFb/LN5qCtxjTkVKtQcLEiSawKSw5z4x43w dMoKglVP8Z/Cfa8mWftKi0owyhQnnLSD/7DRK9F7A7CUToiUdM7D/gl3LuBcnWfEUjWi wn+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h+iPGKjb; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id n14-20020aa7d04e000000b004fd9cad9928si269344edo.40.2023.04.11.18.34.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 18:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=h+iPGKjb; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C6C53858413 for ; Wed, 12 Apr 2023 01:34:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C6C53858413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681263260; bh=iAtRJ38xL5e+z5pZG3Dze3j0v+lX5XfAdyE/BRi1ZBg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=h+iPGKjbIfTbBxE//eSFbBuQ1a5qp6X+vruuhf30R0XeqMKV3uYnpehsLxWU5PbPe xa076f6m/+baeUgG2K3THDMiJryBEG7upE/3+1VYm2piYwSSF8i4w2Kf96WVWiLNxr W/k1d8F5UlFI+jbqMa56UmigIAgoBIwG6WE8elMo= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 703E63858C20 for ; Wed, 12 Apr 2023 01:34:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 703E63858C20 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1a6674bcad4so943165ad.1 for ; Tue, 11 Apr 2023 18:34:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681263251; x=1683855251; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iAtRJ38xL5e+z5pZG3Dze3j0v+lX5XfAdyE/BRi1ZBg=; b=Xpcep4FigrJJI9V/ZG7cNtid90Yahrrd+H9QXHG0RLT3kYLcIHXxKZsD5iaVMeTBdO PgSc6e4QkYK2a+o2gVRBbnHch9juMBZA8DSSA+YJvdYN+wIVBX1Qc8X7WfXHdRu8BTdd NkoU3H6cF7H3EIYdUHnsrK6S3GW10iEznrrwkBtd8N737NvPCpaJusQdBOlCmoQ2r7D8 Uz09fDBuuhD+T3v5LfcwTZT7u5DCbBV24vmTjGNN8dYHwH4H2Qgyd9m6E6WiUx0OwVub 7kdlHflmgjJtvXH4M8WnmVAABwXWve05O8+aqmqMXh73wesKCPUC/yTnien6Z7HnFX2a MUBA== X-Gm-Message-State: AAQBX9f+MuPKRG2JQg1JahbCv1A+6xnf/9nYN48cpQ1cInI+33pXaUJB 9saWzBo3xhBqdvDVHJyBBfKyjPXbEcU= X-Received: by 2002:a62:1ac1:0:b0:62d:d6ca:5834 with SMTP id a184-20020a621ac1000000b0062dd6ca5834mr18306579pfa.16.1681263250986; Tue, 11 Apr 2023 18:34:10 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id 25-20020aa79119000000b005ac419804d3sm10439779pfh.186.2023.04.11.18.34.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Apr 2023 18:34:10 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 4B4AD11432A7; Wed, 12 Apr 2023 11:04:08 +0930 (ACST) Date: Wed, 12 Apr 2023 11:04:08 +0930 To: binutils@sourceware.org Subject: ubsan: dwarf2.c:2232:7: runtime error: index 16 out of bounds Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762932306631898828?= X-GMAIL-MSGID: =?utf-8?q?1762932306631898828?= Except it isn't out of bounds because space for a larger array has been allocated. * dwarf2.c (struct trie_leaf): Make ranges a C99 flexible array. (alloc_trie_leaf, insert_arange_in_trie): Adjust sizing. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index d99508a96c7..b135ef09120 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -137,7 +137,7 @@ struct trie_leaf struct { struct comp_unit *unit; bfd_vma low_pc, high_pc; - } ranges[TRIE_LEAF_SIZE]; + } ranges[]; }; struct trie_interior @@ -148,7 +148,9 @@ struct trie_interior static struct trie_node *alloc_trie_leaf (bfd *abfd) { - struct trie_leaf *leaf = bfd_zalloc (abfd, sizeof (struct trie_leaf)); + struct trie_leaf *leaf; + size_t amt = sizeof (*leaf) + TRIE_LEAF_SIZE * sizeof (leaf->ranges[0]); + leaf = bfd_zalloc (abfd, amt); if (leaf == NULL) return NULL; leaf->head.num_room_in_leaf = TRIE_LEAF_SIZE; @@ -2207,9 +2209,7 @@ insert_arange_in_trie (bfd *abfd, const struct trie_leaf *leaf = (struct trie_leaf *) trie; unsigned int new_room_in_leaf = trie->num_room_in_leaf * 2; struct trie_leaf *new_leaf; - size_t amt = (sizeof (struct trie_leaf) - + ((new_room_in_leaf - TRIE_LEAF_SIZE) - * sizeof (leaf->ranges[0]))); + size_t amt = sizeof (*leaf) + new_room_in_leaf * sizeof (leaf->ranges[0]); new_leaf = bfd_zalloc (abfd, amt); new_leaf->head.num_room_in_leaf = new_room_in_leaf; new_leaf->num_stored_in_leaf = leaf->num_stored_in_leaf;