diff mbox

parser: Fix single-quoted patterns in here-documents

Message ID 20180309150753.GC13375@gondor.apana.org.au (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show

Commit Message

Herbert Xu March 9, 2018, 3:07 p.m. UTC
On Thu, Mar 08, 2018 at 07:35:53PM +0100, Harald van Dijk wrote:
> 
> Related:
> 
>   x=*; cat <<EOF
>   ${x#'*'}
>   EOF
> 
> This shouldn't print anything either: because the * is quoted, it should be
> taken as a literal and removed from $x.
> 
> Re-testing, I see this didn't work properly with my patch either.

I don't think this is related to our patches at all.  It's an
independent bug.  The fix isn't too hard.

---8<---
The script

	x=*
	cat <<- EOF
		${x#'*'}
	EOF

prints * instead of nothing as it should.  The problem is that
when we're in sqsyntax context in a here-document, we won't add
CTLESC as we should.  This patch fixes it:

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Comments

Harald van Dijk March 9, 2018, 7:12 p.m. UTC | #1
On 3/9/18 4:07 PM, Herbert Xu wrote:
> On Thu, Mar 08, 2018 at 07:35:53PM +0100, Harald van Dijk wrote:
>>
>> Related:
>>
>>    x=*; cat <<EOF
>>    ${x#'*'}
>>    EOF
>>
>> This shouldn't print anything either: because the * is quoted, it should be
>> taken as a literal and removed from $x.
>>
>> Re-testing, I see this didn't work properly with my patch either.
> 
> I don't think this is related to our patches at all.

Not related to our patches, but related to the original bug. It's 
another instance where quoted * is wrongly treated as unquoted.

Your fix looks good to me.

Cheers,
Harald van Dijk
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/parser.c b/src/parser.c
index 3aeb9f6..d86d71e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -940,7 +940,8 @@  readtoken1(int firstc, char const *syntax, char *eofmark, int striptabs)
 				USTPUTC(c, out);
 				break;
 			case CCTL:
-				if (eofmark == NULL || synstack->dblquote)
+				if ((!eofmark) | synstack->dblquote |
+				    synstack->varnest)
 					USTPUTC(CTLESC, out);
 				USTPUTC(c, out);
 				break;