From 13028a5a1965588743c61ed2b40781a0cb08b090 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 15 Jul 2009 16:22:47 -0400 Subject: [PATCH] quote: we must do unsigned comparison to get length of octal escape When computing the length of an octal escape, we need to do an unsigned compare, otherwise we only allocate space for one character for bytes in the \200..\377 range, which is obviously incorrect. Reported-by: Ed Beroset Signed-off-by: H. Peter Anvin --- quote.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/quote.c b/quote.c index 5381d043..4cf4f256 100644 --- a/quote.c +++ b/quote.c @@ -48,6 +48,7 @@ char *nasm_quote(char *str, size_t len) { char c, c1, *p, *q, *nstr, *ep; + unsigned char uc; bool sq_ok, dq_ok; size_t qlen; @@ -86,12 +87,12 @@ char *nasm_quote(char *str, size_t len) default: c1 = (p+1 < ep) ? p[1] : 0; if (c1 >= '0' && c1 <= '7') - c1 = 0377; /* Must use the full form */ + uc = 0377; /* Must use the full form */ else - c1 = c; - if (c1 > 077) + uc = c; + if (uc > 077) qlen++; - if (c1 > 07) + if (uc > 07) qlen++; qlen += 2; break; @@ -158,15 +159,15 @@ char *nasm_quote(char *str, size_t len) if (c < ' ' || c > '~') { c1 = (p+1 < ep) ? p[1] : 0; if (c1 >= '0' && c1 <= '7') - c1 = 0377; /* Must use the full form */ + uc = 0377; /* Must use the full form */ else - c1 = c; + uc = c; *q++ = '\\'; - if (c1 > 077) - *q++ = (c >> 6) + '0'; - if (c1 > 07) - *q++ = ((c >> 3) & 7) + '0'; - *q++ = (c & 7) + '0'; + if (uc > 077) + *q++ = ((unsigned char)c >> 6) + '0'; + if (uc > 07) + *q++ = (((unsigned char)c >> 3) & 7) + '0'; + *q++ = ((unsigned char)c & 7) + '0'; break; } else { *q++ = c; -- 2.11.4.GIT