From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 3B06C3858D32 for ; Wed, 9 Nov 2022 07:03:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B06C3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x632.google.com with SMTP id v17so16292982plo.1 for ; Tue, 08 Nov 2022 23:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=jTmsuw9d6s9RQOi1x9iUDDUAdI9QEtEm8X58jRo6bFQ=; b=IioaO0K231JrqtuZWJZQTyEplvdqLpHJ9dq1N3MgaJe1xjYx36jZgUUIO0VfEntOJB bZtugj0ludxpzoJ5VbJonLoaJi2VAvcKJeyG6XyKwp+8SIIHFfChq/V1bBRjvFemOX5L TfjgsRtQEeJbC1ykLFs3E3yDeLrQMnVrKwlvSQ75/uG1sGn0L+H9sC5lkmMw09a0tw12 owQJnjTagA+jhddxpO0L6kvPgs4nj5bXws+yNBTz9xs6BNV0lDOrg9oy8ctjQBKZs0YF SjkPRgEuBmtWnzCxhLP0arYxfwGiO/l+S7f3cwJVRxjLrPuL6ZwSDgz+qq2ZeKsdsV3k f7uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=jTmsuw9d6s9RQOi1x9iUDDUAdI9QEtEm8X58jRo6bFQ=; b=xMBnaNP7U/fGZu8gjdnizYBpI69cxIiyT8yBhYOTlocjJOh8+29vhoqyePs1C8Kw86 0XZTgn8VGqYBnZLhY6H44FCi9DIuI+YL3WJPpbqZOJQ4d5InMW4xHDg0id63aXhHBHlJ ycxAfpCkv9oFMXPq4lAGe+UzjT6681hx+LyauNzLuEhNKkKUBSF9FssZxajUChFpUP0c R7oKWEwd29oDAt1rn9BJ7Wid7pL0NO2rm+VVIwbTwcEIwXK23+nQDykQZHzjuoyC0TNz khPbmfayLQbcfMeUd4D8Hk2FJw+efLLi8aXPL+yWpP1wyameqY1ARtB51zzzprrlH4lY mZ4A== X-Gm-Message-State: ACrzQf0sdxPxHlt7RArXwsnBEgfUIG/8wUlHKW8+V1bmTGYXfaBy4ZfP 7+BBdRs6RW8HCl404n1FltyqR3mfohU= X-Google-Smtp-Source: AMsMyM68RHApVxDxX9vpIwDycdDbncZjs+20T6yr+QYn+grpalPct++VPcJQH0I1/BiMjYzQWTV5IQ== X-Received: by 2002:a17:90a:8a8c:b0:213:c06c:7003 with SMTP id x12-20020a17090a8a8c00b00213c06c7003mr58144904pjn.147.1667977428440; Tue, 08 Nov 2022 23:03:48 -0800 (PST) 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 y28-20020aa79afc000000b005627ddbc7a4sm7518650pfp.191.2022.11.08.23.03.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 23:03:47 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 71B5C11403AC; Wed, 9 Nov 2022 17:33:45 +1030 (ACDT) Date: Wed, 9 Nov 2022 17:33:45 +1030 From: Alan Modra To: binutils@sourceware.org Subject: Re: Fuzzed files in archives Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.2 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 List-Id: Like commit ffbe89531c2e this avoids more silliness writing output that is going to be deleted. bfd_close and bfd_close_all_done differ in that only the former calls _bfd_write_contents. * objcopy.c (copy_archive): Don't call bfd_close for elements that are going to be deleted, call bfd_close_all_done instead. Do the same for the archive itself. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 03350babb69..d886e3ae343 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3670,23 +3670,16 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, if (del && bfd_get_arch (this_element) == bfd_arch_unknown) /* Try again as an unknown object file. */ ok_object = false; - else if (!bfd_close (output_bfd)) - { - bfd_nonfatal_message (output_name, NULL, NULL, NULL); - /* Error in new object file. Don't change archive. */ - status = 1; - } } if (!ok_object) + del = !copy_unknown_object (this_element, output_bfd); + + if (!(ok_object && !del ? bfd_close : bfd_close_all_done) (output_bfd)) { - del = !copy_unknown_object (this_element, output_bfd); - if (!bfd_close_all_done (output_bfd)) - { - bfd_nonfatal_message (output_name, NULL, NULL, NULL); - /* Error in new object file. Don't change archive. */ - status = 1; - } + bfd_nonfatal_message (output_name, NULL, NULL, NULL); + /* Error in new object file. Don't change archive. */ + status = 1; } if (del) @@ -3717,7 +3710,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, *ptr = NULL; filename = bfd_get_filename (obfd); - if (!bfd_close (obfd)) + if (!(status == 0 ? bfd_close : bfd_close_all_done) (obfd)) { status = 1; bfd_nonfatal_message (filename, NULL, NULL, NULL); -- Alan Modra Australia Development Lab, IBM