summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin (Intel) <hpa@zytor.com>2018-06-25 21:20:02 -0700
committerH. Peter Anvin (Intel) <hpa@zytor.com>2018-06-25 21:20:02 -0700
commitd2cdb72e88c093f4c32150142b5ccfb6cf8487c8 (patch)
treec7d9aaad469c9df8d71c24ab45cc54b766bd6596
parent68e7e5dda04012ed5e95407074d3b9d76f6c3b0c (diff)
downloadnasm-d2cdb72e88c093f4c32150142b5ccfb6cf8487c8.tar.gz
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@zytor.com>
-rw-r--r--asm/preproc.c21
-rw-r--r--asm/quote.c2
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 */