mirror of
https://github.com/sheumann/hush.git
synced 2025-02-18 14:30:44 +00:00
ash: fix handling of NULs in $'abc\000def\x00asd'. Closes 9286
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
bcf47eaa1f
commit
13f20919b2
20
shell/ash.c
20
shell/ash.c
@ -5651,6 +5651,10 @@ rmescapes(char *str, int flag)
|
|||||||
}
|
}
|
||||||
if ((unsigned char)*p == CTLESC) {
|
if ((unsigned char)*p == CTLESC) {
|
||||||
p++;
|
p++;
|
||||||
|
#if DEBUG
|
||||||
|
if (*p == '\0')
|
||||||
|
ash_msg_and_raise_error("CTLESC at EOL (shouldn't happen)");
|
||||||
|
#endif
|
||||||
if (protect_against_glob) {
|
if (protect_against_glob) {
|
||||||
*q++ = '\\';
|
*q++ = '\\';
|
||||||
}
|
}
|
||||||
@ -11302,20 +11306,24 @@ readtoken1(int c, int syntax, char *eofmark, int striptabs)
|
|||||||
USTPUTC(c, out);
|
USTPUTC(c, out);
|
||||||
break;
|
break;
|
||||||
case CCTL:
|
case CCTL:
|
||||||
if (eofmark == NULL || dblquote)
|
|
||||||
USTPUTC(CTLESC, out);
|
|
||||||
#if ENABLE_ASH_BASH_COMPAT
|
#if ENABLE_ASH_BASH_COMPAT
|
||||||
if (c == '\\' && bash_dollar_squote) {
|
if (c == '\\' && bash_dollar_squote) {
|
||||||
c = decode_dollar_squote();
|
c = decode_dollar_squote();
|
||||||
|
if (c == '\0') {
|
||||||
|
/* skip $'\000', $'\x00' (like bash) */
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (c & 0x100) {
|
if (c & 0x100) {
|
||||||
USTPUTC('\\', out);
|
/* Unknown escape. Encode as '\z' */
|
||||||
if (eofmark == NULL || dblquote)
|
|
||||||
/* Or else this SEGVs: $'\<0x82>' */
|
|
||||||
USTPUTC(CTLESC, out);
|
|
||||||
c = (unsigned char)c;
|
c = (unsigned char)c;
|
||||||
|
if (eofmark == NULL || dblquote)
|
||||||
|
USTPUTC(CTLESC, out);
|
||||||
|
USTPUTC('\\', out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (eofmark == NULL || dblquote)
|
||||||
|
USTPUTC(CTLESC, out);
|
||||||
USTPUTC(c, out);
|
USTPUTC(c, out);
|
||||||
break;
|
break;
|
||||||
case CBACK: /* backslash */
|
case CBACK: /* backslash */
|
||||||
|
6
shell/ash_test/ash-quoting/dollar_squote_bash2.right
Normal file
6
shell/ash_test/ash-quoting/dollar_squote_bash2.right
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
|
||||||
|
strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
|
||||||
|
80:\€
|
||||||
|
81:\<5C>
|
||||||
|
82:\‚
|
||||||
|
Done:0
|
10
shell/ash_test/ash-quoting/dollar_squote_bash2.tests
Executable file
10
shell/ash_test/ash-quoting/dollar_squote_bash2.tests
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
# Embedded NULs
|
||||||
|
echo $'str\x00'strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
|
||||||
|
echo $'str\000'strstrstrstrstrstrstrstrstrstrstrstrstrstrstrstr
|
||||||
|
|
||||||
|
# The chars after '\' are hex 0x80,81,82...
|
||||||
|
echo 80:$'\€'
|
||||||
|
echo 81:$'\<5C>'
|
||||||
|
echo 82:$'\‚'
|
||||||
|
|
||||||
|
echo Done:$?
|
Loading…
x
Reference in New Issue
Block a user