PR29720, objdump -S crashes if build-id is missing

Message ID Y1jAhwbXhxJHL66v@squeak.grove.modra.org
State Repeat Merge
Headers
Series PR29720, objdump -S crashes if build-id is missing |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Alan Modra Oct. 26, 2022, 5:07 a.m. UTC
  PR 29720
	* objdump.c (slurp_file): Don't call debuginfod_find_source
	when build_id is NULL.
  

Patch

diff --git a/binutils/objdump.c b/binutils/objdump.c
index f7b4695c3e8..a4ab0dbd66c 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1879,17 +1879,19 @@  slurp_file (const char *   fn,
 #if HAVE_LIBDEBUGINFOD
   if (fd < 0 && use_debuginfod && fn[0] == '/' && abfd != NULL)
     {
-      unsigned char * build_id;
-      debuginfod_client * client;
+      unsigned char *build_id = get_build_id (abfd);
 
-      client = debuginfod_begin ();
-      if (client == NULL)
-	return NULL;
+      if (build_id)
+	{
+	  debuginfod_client *client = debuginfod_begin ();
 
-      build_id = get_build_id (abfd);
-      fd = debuginfod_find_source (client, build_id, 0, fn, NULL);
-      free (build_id);
-      debuginfod_end (client);
+	  if (client)
+	    {
+	      fd = debuginfod_find_source (client, build_id, 0, fn, NULL);
+	      debuginfod_end (client);
+	    }
+	  free (build_id);
+	}
     }
 #endif