[Nasm-commits] [nasm:extnames] quote: revert preprocessor behavior
nasm-bot for H. Peter Anvin (Intel)
hpa at zytor.com
Thu Jun 4 19:56:45 PDT 2020
Commit-ID: d2cdb72e88c093f4c32150142b5ccfb6cf8487c8
Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=d2cdb72e88c093f4c32150142b5ccfb6cf8487c8
Author: H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Mon, 25 Jun 2018 21:20:02 -0700
Committer: H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Mon, 25 Jun 2018 21:20:02 -0700
quote: revert preprocessor behavior
Revert the preprocessor to the previous behavior (any non-NUL
character permitted); this allows us to make nasm_unquote_cstr()
reject any control character, too.
Do make nasm_unquote_pp() at least warn on an unterminated string.
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>
---
asm/preproc.c | 21 +++++++++++++++++++--
asm/quote.c | 2 +-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/asm/preproc.c b/asm/preproc.c
index 11d521fb..72d3c447 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -479,11 +479,28 @@ static Token *delete_Token(Token * t);
#define tok_isnt_(x,v) ((x) && ((x)->type!=TOK_OTHER || strcmp((x)->text,(v))))
/*
- * Wrapper for nasm_unquote_cstr()
+ * nasm_unquote with error if the string contains NUL characters.
+ * If the string contains NUL characters, issue an error and return
+ * the C len, i.e. truncate at the NUL.
+ *
+ * This explicitly permits unquoted strings copied verbatim.
*/
static void nasm_unquote_pp(char *qstr, enum preproc_token directive)
{
- nasm_unquote_cstr(qstr, pp_directives[directive]);
+ char qchar = *qstr;
+ char *ep;
+ size_t len = nasm_unquote(qstr, &ep);
+ size_t clen = strlen(qstr);
+
+ if (len != clen) {
+ nasm_error(ERR_NONFATAL,
+ "NUL character in `%s' directive",
+ pp_directives[directive]);
+ } else if (isquote(qchar) && *ep != qchar) {
+ nasm_error(ERR_WARNING|ERR_PASS2,
+ "unterminated string in `%s' directive",
+ pp_directives[directive]);
+ }
}
/*
diff --git a/asm/quote.c b/asm/quote.c
index 8e64dc4a..352876ed 100644
--- a/asm/quote.c
+++ b/asm/quote.c
@@ -498,7 +498,7 @@ char *nasm_unquote_cstr(char *qstr, const char *where)
else
ep++; /* Skip closing quote */
- for (clen = 0; qstr[clen] >= ' ' || qstr[clen] == '\t'; clen++)
+ for (clen = 0; qstr[clen] >= ' '; clen++)
;
qstr[clen] = '\0'; /* Truncate string if necessary */
More information about the Nasm-commits
mailing list