From patchwork Wed Feb 8 02:14:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 64464 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 D93F4385840C for ; Wed, 8 Feb 2023 02:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D93F4385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675822484; bh=2R6Um/3jR30Cb92D6g7t2WS24+MJEcfm7Gkd+aV+UWE=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Help:List-Subscribe:From:Reply-To:From; b=ELZWRt67uV8MD3d1IFq3C59SEFB1br38igL0VeNY1sfa3hVLX7AKm/7RJYs9C8bGO 9V9JSOmiUULzPoWKQzzmDZ3Dn9YLQSDBfl/NaupJzXFmFXKf3ziTdpWbPS/nwB+6Dv /ni/M+mTaMwVHPMbrjREgxHOfZO5mobi5TkZt4nI= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9C9723858C50 for ; Wed, 8 Feb 2023 02:14:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C9723858C50 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-75-VaJcrMjvNru1RNdL4UBRTA-1; Tue, 07 Feb 2023 21:14:33 -0500 X-MC-Unique: VaJcrMjvNru1RNdL4UBRTA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0C5FF1C29D46 for ; Wed, 8 Feb 2023 02:14:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.22.10.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD8C22166B29; Wed, 8 Feb 2023 02:14:32 +0000 (UTC) To: elfutils-devel@sourceware.org Cc: Aaron Merey Subject: [OB PATCH] debuginfod-client.c: Download section even if cached executable didn't contain it. Date: Tue, 7 Feb 2023 21:14:22 -0500 Message-Id: <20230208021422.245352-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aaron Merey via Elfutils-devel From: Aaron Merey Reply-To: Aaron Merey Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" Committing as obvious. Before attempting to download a section, cache_find_section tries to extract the section from existing files in the cache. If it's determined that the section must not exist, cache_find_section returns -ENOENT to indicate that the download should be skipped. This patch fixes a bug where cache_find_section returns -ENOENT even though the section exists. If the cache contains the executable but not the debuginfo with the given build-id and the section only exists in the debuginfo (such as any of the .debug_* sections), then debuginfod_find_section returns -ENOENT even if the section could be downloaded. Fix this by having cache_find_section not return -ENOENT unless cached debuginfo was able to be read. Signed-off-by: Aaron Merey --- debuginfod/ChangeLog | 5 +++++ debuginfod/debuginfod-client.c | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 2ddb7ca0..e961cce9 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -1,3 +1,8 @@ +2023-02-07 Aaron Merey + + * debuginfod-client.c (cache_find_section): Avoid returning -ENOENT if + debuginfo wasn't found. + 2022-12-21 Mark Wielaard * debuginfod-client.c: Define CURL_AT_LEAST_VERSION. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index a16165bd..430d3cf4 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -785,23 +785,24 @@ out: an ELF/DWARF section with name SCN_NAME. If found, extract the section to a separate file in TARGET_CACHE_DIR and return a file descriptor for the section file. The path for this file will be stored in USR_PATH. - Return a negative errno if unsuccessful. */ + Return a negative errno if unsuccessful. -ENOENT indicates that SCN_NAME + is confirmed to not exist. */ static int cache_find_section (const char *scn_name, const char *target_cache_dir, char **usr_path) { - int fd; + int debug_fd; int rc = -EEXIST; char parent_path[PATH_MAX]; /* Check the debuginfo first. */ snprintf (parent_path, PATH_MAX, "%s/debuginfo", target_cache_dir); - fd = open (parent_path, O_RDONLY); - if (fd >= 0) + debug_fd = open (parent_path, O_RDONLY); + if (debug_fd >= 0) { - rc = extract_section (fd, scn_name, parent_path, usr_path); - close (fd); + rc = extract_section (debug_fd, scn_name, parent_path, usr_path); + close (debug_fd); } /* If the debuginfo file couldn't be found or the section type was @@ -809,12 +810,17 @@ cache_find_section (const char *scn_name, const char *target_cache_dir, if (rc == -EEXIST) { snprintf (parent_path, PATH_MAX, "%s/executable", target_cache_dir); - fd = open (parent_path, O_RDONLY); + int exec_fd = open (parent_path, O_RDONLY); - if (fd >= 0) + if (exec_fd >= 0) { - rc = extract_section (fd, scn_name, parent_path, usr_path); - close (fd); + rc = extract_section (exec_fd, scn_name, parent_path, usr_path); + close (exec_fd); + + /* Don't return -ENOENT if the debuginfo wasn't opened. The + section may exist in the debuginfo but not the executable. */ + if (debug_fd < 0 && rc == -ENOENT) + rc = -EREMOTE; } }