From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id BB0433857025 for ; Tue, 24 May 2022 04:19:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB0433857025 Received: by mail-pl1-x631.google.com with SMTP id s14so14827501plk.8 for ; Mon, 23 May 2022 21:19:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=c5BQvyQrxs47zSVv5IPi/1ZMOKPkKDssN8S6GotntS4=; b=bjf3bYxZw3yEIKJ8yudSG/6WAxG2I3bq5CJpNOf/ZZsbibsMzw8DJFT3imgnegPsk7 zAGXfb66Zt7KX8yMKSiMO6morinvjhmZtzR1QKrF3o1sj5CGlFGM361fFO1Vs5xAMP5A rj5UARSe2WPq+KtfNZqZH7hzg2uOOvKX0LHDUOewFCd/nsQM5whsy8AM48SUqHeXOxo4 BtaIxbBk2ywH3lT5fKhWqbz8p6PwySAdWHljejMhdT/vzgr+VyEdSjWX0UKxCXcJUwqr po5gQj+PTA9e4hdsnRCeWRUXkKVd6+5x0n9CZSmJSxGLT3ZXbvaaiX4uPiWhU9OolXm8 mIWQ== X-Gm-Message-State: AOAM531TYrxCYTCyWh6gg6fLkBt74NQahfktI4n7B60jXdd7PQttxHKM 8oeVO89FWxoXMAWf83BydCO6gzUqqKo= X-Google-Smtp-Source: ABdhPJzuKYELocFC0MFIO4vmZh+o/VYDRMsOeh+UVU9ogf/AfpfAqW2bBzDarbgLK9K8cbs8+A9sKw== X-Received: by 2002:a17:90b:1a8a:b0:1e0:3630:19f0 with SMTP id ng10-20020a17090b1a8a00b001e0363019f0mr2533730pjb.89.1653365956726; Mon, 23 May 2022 21:19:16 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:8373:2d95:0:d7a9]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e8d4eb2d1sm5976320pln.283.2022.05.23.21.19.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 21:19:15 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 3054C1140A63; Tue, 24 May 2022 13:49:13 +0930 (ACST) Date: Tue, 24 May 2022 13:49:13 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PR29171, invalid read causing SIGSEGV Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.5 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, 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: 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-List-Received-Date: Tue, 24 May 2022 04:19:20 -0000 The fix here is to pass "section" down to read_and_display_attr_value. The test in read_and_display_attr_value is a little bit of hardening. PR 29171 * dwarf.c (display_debug_macro, display_debug_names): Pass section to read_and_display_attr_value2. (read_and_display_attr_value): Don't attempt to check for .dwo section name when section is NULL. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index d820c21527f..a0dfd4df481 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -2717,7 +2717,7 @@ read_and_display_attr_value (unsigned long attribute, case DW_FORM_strx4: if (!do_loc) { - const char *suffix = strrchr (section->name, '.'); + const char *suffix = section ? strrchr (section->name, '.') : NULL; bool dwo = suffix && strcmp (suffix, ".dwo") == 0; if (do_wide) @@ -6273,8 +6273,9 @@ display_debug_macro (struct dwarf_section *section, SAFE_BYTE_GET_AND_INC (val, desc, 1, end); curr = read_and_display_attr_value (0, val, 0, - start, curr, end, 0, 0, offset_size, - version, NULL, 0, NULL, + start, curr, end, 0, 0, + offset_size, version, + NULL, 0, section, NULL, ' ', -1); if (n != nargs - 1) printf (","); @@ -10310,7 +10311,7 @@ display_debug_names (struct dwarf_section *section, void *file) unit_start, entryptr, unit_end, 0, 0, offset_size, dwarf_version, NULL, - (tagno < 0), NULL, + (tagno < 0), section, NULL, '=', -1); } ++tagno; -- Alan Modra Australia Development Lab, IBM