diff options
author | H. Peter Anvin (Intel) <hpa@zytor.com> | 2019-10-16 15:02:44 -0700 |
---|---|---|
committer | H. Peter Anvin (Intel) <hpa@zytor.com> | 2019-10-16 15:02:44 -0700 |
commit | 18f413422221063d524f7a5b08bece5f8604af27 (patch) | |
tree | 07e2af2301cc03f8337d4c49b41a5c0ef32ee93d /asm | |
parent | e86fa7fffd1789e3b9b2c584d4401dbb6fc92186 (diff) | |
download | nasm-18f413422221063d524f7a5b08bece5f8604af27.tar.gz |
preproc: fix %strcat and %substr
Fix incorrectly running off the end of the intended string for %strcat
and %substr.
This is a modified version of a patch contributed by C. Masloch.
Reported-by: C. Masloch <pushbx@ulukai.org>
Originally-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392599#c11
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Diffstat (limited to 'asm')
-rw-r--r-- | asm/preproc.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/asm/preproc.c b/asm/preproc.c index 785d6e30..c3353951 100644 --- a/asm/preproc.c +++ b/asm/preproc.c @@ -613,6 +613,7 @@ static Token *expand_id(Token * tline); static Context *get_ctx(const char *name, const char **namep); static Token *make_tok_num(Token *next, int64_t val); static Token *make_tok_qstr(Token *next, const char *str); +static Token *make_tok_qstr_len(Token *next, const char *str, size_t len); static Token *make_tok_char(Token *next, char op); static Token *new_Token(Token * next, enum pp_token_type type, const char *text, size_t txtlen); @@ -4238,13 +4239,14 @@ issue_error: if (t->type == TOK_INTERNAL_STRING) q = mempcpy(q, tok_text(t), t->len); } + *q = '\0'; /* * We now have a macro name, an implicit parameter count of * zero, and a numeric token to use as an expansion. Create * and store an SMacro. */ - macro_start = make_tok_qstr(NULL, qbuf); + macro_start = make_tok_qstr_len(NULL, qbuf, len); nasm_free(qbuf); define_smacro(mname, casesense, macro_start, NULL); free_tlist(tline); @@ -4321,7 +4323,7 @@ issue_error: txt = (start < 0) ? "" : tok_text(t) + start; len = count; - macro_start = make_tok_qstr(NULL, txt); + macro_start = make_tok_qstr_len(NULL, txt, len); /* * We now have a macro name, an implicit parameter count of @@ -6571,12 +6573,15 @@ static Token *make_tok_num(Token *next, int64_t val) } /* Create a quoted string token */ -static Token *make_tok_qstr(Token *next, const char *str) +static Token *make_tok_qstr_len(Token *next, const char *str, size_t len) { - size_t len = strlen(str); char *p = nasm_quote(str, &len); return new_Token_free(next, TOK_STRING, p, len); } +static Token *make_tok_qstr(Token *next, const char *str) +{ + return make_tok_qstr_len(next, str, strlen(str)); +} /* Create a single-character operator token */ static Token *make_tok_char(Token *next, char op) |