diff options
author | jilles <jilles@FreeBSD.org> | 2015-08-20 22:05:55 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2015-08-20 22:05:55 +0000 |
commit | 5e4f40c860b60f76a46b999cdc2606ac287a975c (patch) | |
tree | 05d618ef5ca7326b6ea958cfab1a7b22de13d4f4 /bin/sh/parser.c | |
parent | 4485ab4d3d63c821390eecb708c6ba6bfccdbe8f (diff) | |
download | FreeBSD-src-5e4f40c860b60f76a46b999cdc2606ac287a975c.zip FreeBSD-src-5e4f40c860b60f76a46b999cdc2606ac287a975c.tar.gz |
sh: Avoid negative character values from $'\Uffffffff' etc.
The negative value was not expected and generated the low 8 bits as a byte,
which may be an invalid character encoding.
The final shift in creating the negative value was undefined as well.
Make the temporary variable unsigned to fix this.
Diffstat (limited to 'bin/sh/parser.c')
-rw-r--r-- | bin/sh/parser.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index 2bba84e..e7ec010 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1195,7 +1195,8 @@ parsebackq(char *out, struct nodelist **pbqlist, static char * readcstyleesc(char *out) { - int c, v, i, n; + int c, vc, i, n; + unsigned int v; c = pgetc(); switch (c) { @@ -1310,12 +1311,12 @@ readcstyleesc(char *out) default: synerror("Bad escape sequence"); } - v = (char)v; + vc = (char)v; /* * We can't handle NUL bytes. * POSIX says we should skip till the closing quote. */ - if (v == '\0') { + if (vc == '\0') { while ((c = pgetc()) != '\'') { if (c == '\\') c = pgetc(); @@ -1332,9 +1333,9 @@ readcstyleesc(char *out) pungetc(); return out; } - if (SQSYNTAX[v] == CCTL) + if (SQSYNTAX[vc] == CCTL) USTPUTC(CTLESC, out); - USTPUTC(v, out); + USTPUTC(vc, out); return out; } |