Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 40eb8b9

Browse files
committed
Don't return the main file as the separate debug info
On Fedora 35, $ readelf -d /usr/bin/npc caused readelf to run out of stack since load_separate_debug_info returned the input main file as the separate debug info: (gdb) bt #0 load_separate_debug_info ( main_filename=main_filename@entry=0x510f50 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo", xlink=xlink@entry=0x4e5180 <debug_displays+4480>, parse_func=parse_func@entry=0x431550 <parse_gnu_debuglink>, check_func=check_func@entry=0x432ae0 <check_gnu_debuglink>, func_data=func_data@entry=0x7fffffffdb60, file=file@entry=0x51d430) at /export/gnu/import/git/sources/binutils-gdb/binutils/dwarf.c:11057 #1 0x000000000043328d in check_for_and_load_links (file=0x51d430, filename=0x510f50 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo") at /export/gnu/import/git/sources/binutils-gdb/binutils/dwarf.c:11381 #2 0x00000000004332ae in check_for_and_load_links (file=0x51b070, filename=0x518dd0 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo") Return NULL if the separate debug info is the same as the input main file to avoid infinite recursion. PR binutils/28679 * dwarf.c (load_separate_debug_info): Don't return the input main file.
1 parent 1563e71 commit 40eb8b9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

binutils/dwarf.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -11053,6 +11053,9 @@ load_separate_debug_info (const char * main_filename,
1105311053
char * canon_dir;
1105411054
size_t canon_dirlen;
1105511055
size_t dirlen;
11056+
char * canon_filename;
11057+
char * canon_debug_filename;
11058+
bool self;
1105611059

1105711060
if ((separate_filename = parse_func (xlink, func_data)) == NULL)
1105811061
{
@@ -11064,7 +11067,8 @@ load_separate_debug_info (const char * main_filename,
1106411067
/* Attempt to locate the separate file.
1106511068
This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
1106611069

11067-
canon_dir = lrealpath (main_filename);
11070+
canon_filename = lrealpath (main_filename);
11071+
canon_dir = xstrdup (canon_filename);
1106811072

1106911073
for (canon_dirlen = strlen (canon_dir); canon_dirlen > 0; canon_dirlen--)
1107011074
if (IS_DIR_SEPARATOR (canon_dir[canon_dirlen - 1]))
@@ -11096,6 +11100,7 @@ load_separate_debug_info (const char * main_filename,
1109611100
{
1109711101
warn (_("Out of memory"));
1109811102
free (canon_dir);
11103+
free (canon_filename);
1109911104
return NULL;
1110011105
}
1110111106

@@ -11214,11 +11219,22 @@ load_separate_debug_info (const char * main_filename,
1121411219

1121511220
free (canon_dir);
1121611221
free (debug_filename);
11222+
free (canon_filename);
1121711223
return NULL;
1121811224

1121911225
found:
1122011226
free (canon_dir);
1122111227

11228+
canon_debug_filename = lrealpath (debug_filename);
11229+
self = strcmp (canon_debug_filename, canon_filename) == 0;
11230+
free (canon_filename);
11231+
free (canon_debug_filename);
11232+
if (self)
11233+
{
11234+
free (debug_filename);
11235+
return NULL;
11236+
}
11237+
1122211238
void * debug_handle;
1122311239

1122411240
/* Now open the file.... */

0 commit comments

Comments
 (0)