From 385d3e9c53ea128cee2459f5e6302a386704c907 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Tue, 13 Jul 2010 19:08:15 +0400 Subject: BR3028880: Fix NULL dereference on nonexistent environment variable Frank reported we hit NULL dereference on nonexistent environment variables. Fix it by leaving empty string in text field of such token and yielding warning. Reported-by: Frank Kotler Signed-off-by: Cyrill Gorcunov --- preproc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'preproc.c') diff --git a/preproc.c b/preproc.c index ef4f95c3..09ef32b6 100644 --- a/preproc.c +++ b/preproc.c @@ -1181,11 +1181,14 @@ static char *detoken(Token * tlist, bool expand_locals) list_for_each(t, tlist) { if (t->type == TOK_PREPROC_ID && t->text[1] == '!') { char *p = getenv(t->text + 2); - nasm_free(t->text); - if (p) + char *q = t->text; + if (p) { t->text = nasm_strdup(p); - else - t->text = NULL; + } else { + t->text = nasm_strdup(""); + error(ERR_WARNING | ERR_PASS1, "`%s' is empty", q + 2); + } + nasm_free(q); } /* Expand local macros here and not during preprocessing */ if (expand_locals && -- cgit v1.2.1