public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: elfutils-devel@sourceware.org
Cc: Aaron Merey <amerey@redhat.com>
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	[thread overview]
Message-ID: <20230208021422.245352-1-amerey@redhat.com> (raw)

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 <amerey@redhat.com>
---
 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  <amerey@redhat.com>
+
+	* debuginfod-client.c (cache_find_section): Avoid returning -ENOENT if
+	debuginfo wasn't found.
+
 2022-12-21  Mark Wielaard  <mark@klomp.org>
 
 	* 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;
 	}
     }
 
-- 
2.39.1


                 reply	other threads:[~2023-02-08  2:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208021422.245352-1-amerey@redhat.com \
    --to=amerey@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).