ash: sync up with dash with respect to redirection escaping

We fixed the problem differently than they. Let's not deviate.

Upstream commit:

    Date: Thu, 27 May 2010 20:07:29 +1000
    [EXPAND] Fix corruption of redirections with byte 0x81

    In other ash variants, a partial implementation of ksh-like cmd >file*
    adds and removes CTLESC bytes ('\x81') in redirection filenames,
    preserving 8-bit transparency. Long ago, dash removed the code to add
    the CTLESC bytes, but not the code to remove them, causing corruption of
    filenames containing CTLESC. This commit removes the code to remove the
    CTLESC bytes.

    The CTLESC byte occurs frequently in UTF-8 encoded non-Latin text.

    This bug has been reported various times to Ubuntu and Debian (e.g.
    Launchpad Ubuntu #422298). This patch is the same as the one submitted
    by Alexander Korolkov in Ubuntu #422298.

    Signed-off-by: Jilles Tjoelker <jilles@stack.nl>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

function                                             old     new   delta
changepath                                           194     192      -2
expandarg                                           1000     984     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-18)             Total: -18 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-07-25 17:37:57 +02:00
parent b28d4c3462
commit 2990aa45d1

View File

@ -5711,7 +5711,7 @@ ash_arith(const char *s)
#define RMESCAPE_SLASH 0x20 /* Stop globbing after slash */
/* Add CTLESC when necessary. */
#define QUOTES_ESC (EXP_FULL | EXP_CASE | EXP_QPAT | EXP_REDIR)
#define QUOTES_ESC (EXP_FULL | EXP_CASE | EXP_QPAT)
/* Do not skip NUL characters. */
#define QUOTES_KEEPNUL EXP_TILDE
@ -7608,10 +7608,6 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
exparg.lastp = &exparg.list;
expandmeta(exparg.list /*, flag*/);
} else {
if (flag & EXP_REDIR) { /*XXX - for now, just remove escapes */
rmescapes(p, 0);
TRACE(("expandarg: rmescapes:'%s'\n", p));
}
sp = stzalloc(sizeof(*sp));
sp->text = p;
*exparg.lastp = sp;