This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Invalid use of positional arguments in nm -f bsd
- From: Petr Machata <pmachata at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Mon, 30 Jul 2012 15:04:29 +0200
- Subject: Invalid use of positional arguments in nm -f bsd
Hi list,
the problem is reproduced when building elfutils with
-D_FORTIFY_SOURCE=2 and then:
# ./src/nm -f bsd ./src/nm
*** invalid %N$ use detected ***
Aborted
The problem is in the following suite of format strings in nm.c:
[radix_hex] = "%8$s%2$0*1$" PRIx64 "%10$s %9$s%3$c%4$s %5$s",
[radix_decimal] = "%8$s%*" PRId64 "%10$s %9$s%3$c%4$s %5$s",
[radix_octal] = "%8$s%2$0*1$" PRIo64 "%10$s %9$s%3$c%4$s %5$s"
Note that 6$ and 7$ are missing, which is not allowed. With
_FORTIFY_SOURCE, glibc actually detects this condition and aborts.
printf is actually given all 10 arguments, and in another branch a
different set of formatting arguments are used, and those do contain 6$
and 7$. In the patch I reorder the arguments so that 6$ and 7$ become
9$ and 10$, and there are no gaps in any of the formatting strings.
Thanks,
PM
>From 824ccb88054cf93f23966e2fb0be2d22bb70f322 Mon Sep 17 00:00:00 2001
From: Petr Machata <pmachata@redhat.com>
Date: Mon, 30 Jul 2012 15:00:56 +0200
Subject: [PATCH] Reorder formatting string arguments so that there are no
gaps in references
It is required that formatting string that uses $-style references lists
all arguments.
---
src/ChangeLog | 6 ++++++
src/nm.c | 16 ++++++++--------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index aa7e2a5..d05bb2e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2012-07-30 Petr Machata <pmachata@redhat.com>
+
+ * nm.c (show_symbols_bsd): Reorder arguments in {S,}FMTSTRS (and
+ corresponding printf) so that those that are referenced by only
+ one of the formatting strings are at the end.
+
2012-07-29 Mark Wielaard <mjw@redhat.com>
* readelf.c (dwarf_lang_string): Use DW_LANG_ObjC, not DW_LANG_Objc.
diff --git a/src/nm.c b/src/nm.c
index 7db6fb8..f50da0b 100644
--- a/src/nm.c
+++ b/src/nm.c
@@ -929,15 +929,15 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
static const char *const fmtstrs[] =
{
- [radix_hex] = "%8$s%2$0*1$" PRIx64 "%10$s %9$s%3$c%4$s %5$s",
- [radix_decimal] = "%8$s%*" PRId64 "%10$s %9$s%3$c%4$s %5$s",
- [radix_octal] = "%8$s%2$0*1$" PRIo64 "%10$s %9$s%3$c%4$s %5$s"
+ [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %7$s%3$c%4$s %5$s",
+ [radix_decimal] = "%6$s%*" PRId64 "%8$s %7$s%3$c%4$s %5$s",
+ [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %7$s%3$c%4$s %5$s"
};
static const char *const sfmtstrs[] =
{
- [radix_hex] = "%8$s%2$0*1$" PRIx64 "%10$s %7$0*6$" PRIx64 " %9$s%3$c%4$s %5$s",
- [radix_decimal] = "%8$s%2$*1$" PRId64 "%10$s %7$*6$" PRId64 " %9$s%3$c%4$s %5$s",
- [radix_octal] = "%8$s%2$0*1$" PRIo64 "%10$s %7$0*6$" PRIo64 " %9$s%3$c%4$s %5$s"
+ [radix_hex] = "%6$s%2$0*1$" PRIx64 "%8$s %10$0*9$" PRIx64 " %7$s%3$c%4$s %5$s",
+ [radix_decimal] = "%6$s%2$*1$" PRId64 "%8$s %10$*9$" PRId64 " %7$s%3$c%4$s %5$s",
+ [radix_octal] = "%6$s%2$0*1$" PRIo64 "%8$s %10$0*9$" PRIo64 " %7$s%3$c%4$s %5$s"
};
#ifdef USE_DEMANGLE
@@ -1020,10 +1020,10 @@ show_symbols_bsd (Elf *elf, const GElf_Ehdr *ehdr, GElf_Word strndx,
digits, syms[cnt].sym.st_value,
class_type_char (elf, ehdr, &syms[cnt].sym), marker,
symstr,
- digits, (uint64_t) syms[cnt].sym.st_size,
color_mode ? color_address : "",
color,
- color_mode ? color_off : "");
+ color_mode ? color_off : "",
+ digits, (uint64_t) syms[cnt].sym.st_size);
}
if (color_mode)
--
1.7.6.5