diff options
author | Denys Vlasenko | 2016-09-25 20:54:25 +0200 |
---|---|---|
committer | Denys Vlasenko | 2016-09-25 20:54:25 +0200 |
commit | 13f20919b2477230063bb940396bef51b463d6df (patch) | |
tree | 0b5f9053840208d92d70a4f6fe13ef2a5cb50604 /shell/ash.c | |
parent | bcf47eaa1f13dfdcc4564ddb1e5aedce4b3ca2b2 (diff) | |
download | busybox-13f20919b2477230063bb940396bef51b463d6df.zip busybox-13f20919b2477230063bb940396bef51b463d6df.tar.gz |
ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/shell/ash.c b/shell/ash.c index 2674937..578b3dc 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -5651,6 +5651,10 @@ rmescapes(char *str, int flag) } if ((unsigned char)*p == CTLESC) { p++; +#if DEBUG + if (*p == '\0') + ash_msg_and_raise_error("CTLESC at EOL (shouldn't happen)"); +#endif if (protect_against_glob) { *q++ = '\\'; } @@ -11302,20 +11306,24 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs) USTPUTC(c, out); break; case CCTL: - if (eofmark == NULL || dblquote) - USTPUTC(CTLESC, out); #if ENABLE_ASH_BASH_COMPAT if (c == '\\' && bash_dollar_squote) { c = decode_dollar_squote(); + if (c == '\0') { + /* skip $'\000', $'\x00' (like bash) */ + break; + } if (c & 0x100) { - USTPUTC('\\', out); + /* Unknown escape. Encode as '\z' */ + c = (unsigned char)c; if (eofmark == NULL || dblquote) - /* Or else this SEGVs: $'\<0x82>' */ USTPUTC(CTLESC, out); - c = (unsigned char)c; + USTPUTC('\\', out); } } #endif + if (eofmark == NULL || dblquote) + USTPUTC(CTLESC, out); USTPUTC(c, out); break; case CBACK: /* backslash */ |