← Commit list

eb54ca8be

Denys Vlasenko
Denys Vlasenko
2018-08-07
SUCCESS Duration: 147s

Subject

ash: expand: Do not quote backslashes in unquoted parameter expansion

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

shell/ash.c+4 -6
@@ -6236,9 +6236,7 @@ memtodest(const char *p, size_t len, int syntax, int quotes)
if (quotes & QUOTES_ESC) {
int n = SIT(c, syntax);
if (n == CCTL
- || (((quotes & EXP_FULL) || syntax != BASESYNTAX)
- && n == CBACK
- )
+ || (syntax != BASESYNTAX && n == CBACK)
) {
USTPUTC(CTLESC, q);
}
@@ -7639,7 +7637,7 @@ expmeta(exp_t *exp, char *name, unsigned name_len, unsigned expdir_len)
}
}
} else {
- if (*p == '\\')
+ if (*p == '\\' && p[1])
esc++;
if (p[esc] == '/') {
if (metaflag)
@@ -7653,7 +7651,7 @@ expmeta(exp_t *exp, char *name, unsigned name_len, unsigned expdir_len)
return;
p = name;
do {
- if (*p == '\\')
+ if (*p == '\\' && p[1])
p++;
*enddir++ = *p;
} while (*p++);
@@ -7665,7 +7663,7 @@ expmeta(exp_t *exp, char *name, unsigned name_len, unsigned expdir_len)
if (name < start) {
p = name;
do {
- if (*p == '\\')
+ if (*p == '\\' && p[1])
p++;
*enddir++ = *p++;
} while (p < start);
shell/ash_test/ash-glob/glob_bkslash_in_var.right+4 -0
@@ -0,0 +1,4 @@
+Unquoted non-matching glob in var:'test*.TMP/\name_doesnt_exist'
+Unquoted matching glob in var: 'testdir.TMP/name'
+Quoted non-matching glob in var: 'test*.TMP/\name_doesnt_exist'
+Quoted matching glob in var: 'test*.TMP/\name'
shell/ash_test/ash-glob/glob_bkslash_in_var.tests+10 -0
@@ -0,0 +1,10 @@
+mkdir testdir.TMP
+>testdir.TMP/name
+a="test*.TMP/\name_doesnt_exist"
+b="test*.TMP/\name"
+printf "Unquoted non-matching glob in var:'%s'\n" $a
+printf "Unquoted matching glob in var: '%s'\n" $b
+printf "Quoted non-matching glob in var: '%s'\n" "$a"
+printf "Quoted matching glob in var: '%s'\n" "$b"
+rm -f testdir.TMP/name
+rmdir testdir.TMP
shell/hush_test/hush-glob/glob_bkslash_in_var.right+4 -0
@@ -0,0 +1,4 @@
+Unquoted non-matching glob in var:'test*.TMP/\name_doesnt_exist'
+Unquoted matching glob in var: 'testdir.TMP/name'
+Quoted non-matching glob in var: 'test*.TMP/\name_doesnt_exist'
+Quoted matching glob in var: 'test*.TMP/\name'
shell/hush_test/hush-glob/glob_bkslash_in_var.tests+10 -0
@@ -0,0 +1,10 @@
+mkdir testdir.TMP
+>testdir.TMP/name
+a="test*.TMP/\name_doesnt_exist"
+b="test*.TMP/\name"
+printf "Unquoted non-matching glob in var:'%s'\n" $a
+printf "Unquoted matching glob in var: '%s'\n" $b
+printf "Quoted non-matching glob in var: '%s'\n" "$a"
+printf "Quoted matching glob in var: '%s'\n" "$b"
+rm -f testdir.TMP/name
+rmdir testdir.TMP