Module Name:    src
Committed By:   christos
Date:           Mon Feb 22 20:02:00 UTC 2016

Modified Files:
        src/bin/sh: expand.c parser.c parser.h

Log Message:
PR bin/43469 - correctly handle quoting of the pattern part of ${var%pat}
type expansions. (from kre)


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/bin/sh/expand.c
cvs rdiff -u -r1.97 -r1.98 src/bin/sh/parser.c
cvs rdiff -u -r1.18 -r1.19 src/bin/sh/parser.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/expand.c
diff -u src/bin/sh/expand.c:1.93 src/bin/sh/expand.c:1.94
--- src/bin/sh/expand.c:1.93	Thu Aug 27 03:46:47 2015
+++ src/bin/sh/expand.c	Mon Feb 22 15:02:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.93 2015/08/27 07:46:47 christos Exp $	*/
+/*	$NetBSD: expand.c,v 1.94 2016/02/22 20:02:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)expand.c	8.5 (Berkeley) 5/15/95";
 #else
-__RCSID("$NetBSD: expand.c,v 1.93 2015/08/27 07:46:47 christos Exp $");
+__RCSID("$NetBSD: expand.c,v 1.94 2016/02/22 20:02:00 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -511,7 +511,7 @@ subevalvar(char *p, char *str, int strlo
 	case VSTRIMLEFTMAX:
 	case VSTRIMRIGHT:
 	case VSTRIMRIGHTMAX:
-		how = (varflags & VSQUOTE) ? 0 : EXP_CASE;
+		how = (varflags & (VSQUOTE|VSPATQ)) == VSQUOTE ? 0 : EXP_CASE;
 		break;
 	default:
 		how = 0;

Index: src/bin/sh/parser.c
diff -u src/bin/sh/parser.c:1.97 src/bin/sh/parser.c:1.98
--- src/bin/sh/parser.c:1.97	Mon Feb 22 14:42:46 2016
+++ src/bin/sh/parser.c	Mon Feb 22 15:02:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.c,v 1.97 2016/02/22 19:42:46 christos Exp $	*/
+/*	$NetBSD: parser.c,v 1.98 2016/02/22 20:02:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)parser.c	8.7 (Berkeley) 5/16/95";
 #else
-__RCSID("$NetBSD: parser.c,v 1.97 2016/02/22 19:42:46 christos Exp $");
+__RCSID("$NetBSD: parser.c,v 1.98 2016/02/22 20:02:00 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -1517,6 +1517,8 @@ badsub:
 		}
 		if (ISDBLQUOTE() || arinest)
 			flags |= VSQUOTE;
+		if (subtype >= VSTRIMLEFT && subtype <= VSTRIMRIGHTMAX)
+			flags |= VSPATQ;
 		*(stackblock() + typeloc) = subtype | flags;
 		if (subtype != VSNORMAL) {
 			TS_PUSH();

Index: src/bin/sh/parser.h
diff -u src/bin/sh/parser.h:1.18 src/bin/sh/parser.h:1.19
--- src/bin/sh/parser.h:1.18	Wed Oct  2 15:52:58 2013
+++ src/bin/sh/parser.h	Mon Feb 22 15:02:00 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: parser.h,v 1.18 2013/10/02 19:52:58 christos Exp $	*/
+/*	$NetBSD: parser.h,v 1.19 2016/02/22 20:02:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -53,6 +53,7 @@
 #define VSNUL		0x10	/* colon--treat the empty string as unset */
 #define VSLINENO	0x20	/* expansion of $LINENO, the line number
 				   follows immediately */
+#define VSPATQ		0x40	/* ensure correct pattern quoting in ${x#pat} */
 #define VSQUOTE	 	0x80	/* inside double quotes--suppress splitting */
 
 /* values of VSTYPE field */

Reply via email to