diff options
author | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-07-13 19:08:15 +0400 |
---|---|---|
committer | Cyrill Gorcunov <gorcunov@gmail.com> | 2010-07-13 21:17:24 +0400 |
commit | 385d3e9c53ea128cee2459f5e6302a386704c907 (patch) | |
tree | 322c807ac6fcd527d7e0d3737504ed910fd50839 | |
parent | c6360a757b8c4284e416aa8025352045cffbf743 (diff) | |
download | nasm-385d3e9c53ea128cee2459f5e6302a386704c907.tar.gz |
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 <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
-rw-r--r-- | preproc.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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 && |