From 7d231b33782ce8d89ea974b3ca21b55a71642b92 Mon Sep 17 00:00:00 2001 From: John Marino Date: Sat, 17 Mar 2012 11:23:45 +0100 Subject: [PATCH] rtld: Don't use toupper function in rtld_printf.c The libc function toupper may not function correctly due to TLS use when LD_DEBUG is in effect. Rather than determine this for sure, just use the FreeBSD approach of eliminating ctype.h macro. Taken from: FreeBSD SVN 232729 (2012-03-09) --- libexec/rtld-elf/map_object.c | 2 -- libexec/rtld-elf/rtld_printf.c | 12 +++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libexec/rtld-elf/map_object.c b/libexec/rtld-elf/map_object.c index a90a29e91e..ffb816a346 100644 --- a/libexec/rtld-elf/map_object.c +++ b/libexec/rtld-elf/map_object.c @@ -65,7 +65,6 @@ map_object(int fd, const char *path, const struct stat *sb) Elf_Phdr *phtls; caddr_t mapbase; size_t mapsize; - Elf_Off base_offset; Elf_Addr base_vaddr; Elf_Addr base_vlimit; caddr_t base_addr; @@ -161,7 +160,6 @@ map_object(int fd, const char *path, const struct stat *sb) * Map the entire address space of the object, to stake out our * contiguous region, and to establish the base address for relocation. */ - base_offset = trunc_page(segs[0]->p_offset); base_vaddr = trunc_page(segs[0]->p_vaddr); base_vlimit = round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_memsz); mapsize = base_vlimit - base_vaddr; diff --git a/libexec/rtld-elf/rtld_printf.c b/libexec/rtld-elf/rtld_printf.c index b9aadc3587..eb4514a390 100644 --- a/libexec/rtld-elf/rtld_printf.c +++ b/libexec/rtld-elf/rtld_printf.c @@ -36,7 +36,6 @@ */ #include -#include #include #include #include @@ -90,8 +89,10 @@ snprintf_func(int ch, struct snprintf_arg *const info) } } -static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; -#define hex2ascii(hex) (hex2ascii_data[hex]) +static char const hex2ascii_lower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; +static char const hex2ascii_upper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +#define hex2ascii(hex) (hex2ascii_lower[hex]) +#define hex2ascii_upper(hex) (hex2ascii_upper[hex]) static __inline int imax(int a, int b) @@ -108,8 +109,9 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) p = nbuf; *p = '\0'; do { - c = hex2ascii(num % base); - *++p = upper ? toupper(c) : c; + c = upper ? hex2ascii_upper(num % base) : + hex2ascii(num % base); + *++p = c; } while (num /= base); if (lenp) *lenp = p - nbuf; -- 2.41.0