From 79a70cccd8ef21dff5b9c4442143199e469662b2 Mon Sep 17 00:00:00 2001 From: kib Date: Mon, 5 Mar 2012 20:43:06 +0000 Subject: [PATCH 126/175] The libmap.conf initialization is performed before TLS is functional. Since after r232498 the ctype macros require working access to thread-local variables, rtld crashes when libmap.conf is present. Use hand-made isspace1() macro which is enough to detect spaces in libmap.conf. Reported by: alc, lme, many on current@ Tested by: lme Reviewed by: dim, kan MFC after: 1 week git-svn-id: http://svn.freebsd.org/base/head@232572 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f (cherry picked from commit 71d6e02b5a9ff8d8f561353a1500a50d52e195e7) Signed-off-by: Xin Li --- libexec/rtld-elf/libmap.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/libexec/rtld-elf/libmap.c b/libexec/rtld-elf/libmap.c index 773456b..9c67186 100644 --- a/libexec/rtld-elf/libmap.c +++ b/libexec/rtld-elf/libmap.c @@ -3,7 +3,6 @@ */ #include -#include #include #include #include @@ -53,6 +52,12 @@ static int closestrfn (void * cookie); #define iseol(c) (((c) == '#') || ((c) == '\0') || \ ((c) == '\n') || ((c) == '\r')) +/* + * Do not use ctype.h macros, which rely on working TLS. It is + * too early to have thread-local variables functional. + */ +#define isspace1(c) ((c) == ' ' || (c) == '\t') + int lm_init (char *libmap_override) { @@ -107,7 +112,7 @@ lmc_parse (FILE *fp) t = f = c = NULL; /* Skip over leading space */ - while (isspace(*cp)) cp++; + while (isspace1(*cp)) cp++; /* Found a comment or EOL */ if (iseol(*cp)) continue; @@ -117,7 +122,7 @@ lmc_parse (FILE *fp) cp++; /* Skip leading space */ - while (isspace(*cp)) cp++; + while (isspace1(*cp)) cp++; /* Found comment, EOL or end of selector */ if (iseol(*cp) || *cp == ']') @@ -125,11 +130,11 @@ lmc_parse (FILE *fp) c = cp++; /* Skip to end of word */ - while (!isspace(*cp) && !iseol(*cp) && *cp != ']') + while (!isspace1(*cp) && !iseol(*cp) && *cp != ']') cp++; /* Skip and zero out trailing space */ - while (isspace(*cp)) *cp++ = '\0'; + while (isspace1(*cp)) *cp++ = '\0'; /* Check if there is a closing brace */ if (*cp != ']') continue; @@ -141,7 +146,7 @@ lmc_parse (FILE *fp) * There should be nothing except whitespace or comment from this point to the end of the line. */ - while(isspace(*cp)) cp++; + while(isspace1(*cp)) cp++; if (!iseol(*cp)) continue; strcpy(prog, c); @@ -151,20 +156,20 @@ lmc_parse (FILE *fp) /* Parse the 'from' candidate. */ f = cp++; - while (!isspace(*cp) && !iseol(*cp)) cp++; + while (!isspace1(*cp) && !iseol(*cp)) cp++; /* Skip and zero out the trailing whitespace */ - while (isspace(*cp)) *cp++ = '\0'; + while (isspace1(*cp)) *cp++ = '\0'; /* Found a comment or EOL */ if (iseol(*cp)) continue; /* Parse 'to' mapping */ t = cp++; - while (!isspace(*cp) && !iseol(*cp)) cp++; + while (!isspace1(*cp) && !iseol(*cp)) cp++; /* Skip and zero out the trailing whitespace */ - while (isspace(*cp)) *cp++ = '\0'; + while (isspace1(*cp)) *cp++ = '\0'; /* Should be no extra tokens at this point */ if (!iseol(*cp)) continue; -- 1.7.9.4