From b937534868c8d7aec3b6d645bf5fd657bbfccd42 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Wed, 29 May 2013 21:30:20 +0530 Subject: Avoid crashing in LD_DEBUG when program name is unavailable Resolves: #15465 The program name may be unavailable if the user application tampers with argc and argv[]. Some parts of the dynamic linker caters for this while others don't, so this patch consolidates the check and fallback into a single macro and updates all users. --- elf/dl-lookup.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'elf/dl-lookup.c') diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c index 68f8dac..39f463e 100644 --- a/elf/dl-lookup.c +++ b/elf/dl-lookup.c @@ -112,8 +112,7 @@ do_lookup_x (const char *undef_name, uint_fast32_t new_hash, /* Print some debugging info if wanted. */ if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_SYMBOLS, 0)) _dl_debug_printf ("symbol=%s; lookup in file=%s [%lu]\n", - undef_name, - map->l_name[0] ? map->l_name : rtld_progname, + undef_name, DSO_FILENAME (map->l_name), map->l_ns); /* If the hash table is empty there is nothing to do here. */ @@ -667,10 +666,9 @@ add_dependency (struct link_map *undef_map, struct link_map *map, int flags) if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)) _dl_debug_printf ("\ \nfile=%s [%lu]; needed by %s [%lu] (relocation dependency)\n\n", - map->l_name[0] ? map->l_name : rtld_progname, + DSO_FILENAME (map->l_name), map->l_ns, - undef_map->l_name[0] - ? undef_map->l_name : rtld_progname, + DSO_FILENAME (undef_map->l_name), undef_map->l_ns); } else @@ -751,9 +749,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, const char *reference_name = undef_map ? undef_map->l_name : NULL; /* XXX We cannot translate the message. */ - _dl_signal_cerror (0, (reference_name[0] - ? reference_name - : (rtld_progname ?: "
")), + _dl_signal_cerror (0, DSO_FILENAME (reference_name), N_("relocation error"), make_string ("symbol ", undef_name, ", version ", version->name, @@ -780,9 +776,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map, ? version->name : ""); /* XXX We cannot translate the message. */ - _dl_signal_cerror (0, (reference_name[0] - ? reference_name - : (rtld_progname ?: "
")), + _dl_signal_cerror (0, DSO_FILENAME (reference_name), N_("symbol lookup error"), make_string (undefined_msg, undef_name, versionstr, versionname)); @@ -912,11 +906,9 @@ _dl_debug_bindings (const char *undef_name, struct link_map *undef_map, if (GLRO(dl_debug_mask) & DL_DEBUG_BINDINGS) { _dl_debug_printf ("binding file %s [%lu] to %s [%lu]: %s symbol `%s'", - (reference_name[0] - ? reference_name - : (rtld_progname ?: "
")), + DSO_FILENAME (reference_name), undef_map->l_ns, - value->m->l_name[0] ? value->m->l_name : rtld_progname, + DSO_FILENAME (value->m->l_name), value->m->l_ns, protected ? "protected" : "normal", undef_name); if (version) -- cgit v1.1