summaryrefslogtreecommitdiff
path: root/preproc.c
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2010-07-13 19:08:15 +0400
committerCyrill Gorcunov <gorcunov@gmail.com>2010-07-13 21:17:24 +0400
commit385d3e9c53ea128cee2459f5e6302a386704c907 (patch)
tree322c807ac6fcd527d7e0d3737504ed910fd50839 /preproc.c
parentc6360a757b8c4284e416aa8025352045cffbf743 (diff)
downloadnasm-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>
Diffstat (limited to 'preproc.c')
-rw-r--r--preproc.c11
1 files changed, 7 insertions, 4 deletions
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 &&