From eikemeier@fillmore-labs.com  Wed Jan 21 03:58:24 2004
Return-Path: <eikemeier@fillmore-labs.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4B5E116A4CF
	for <FreeBSD-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 03:58:24 -0800 (PST)
Received: from postman.arcor.de (postman4.arcor-online.net [151.189.0.189])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 734FE43D64
	for <FreeBSD-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 03:58:11 -0800 (PST)
	(envelope-from eikemeier@fillmore-labs.com)
Received: from fillmore.dyndns.org (port-212-202-51-21.reverse.qsc.de [212.202.51.21])
	(authenticated bits=0)
	by postman.arcor.de (8.13.0.PreAlpha4/8.13.0.PreAlpha4) with ESMTP id i0LBw8M4023011
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO)
	for <FreeBSD-gnats-submit@FreeBSD.org>; Wed, 21 Jan 2004 12:58:09 +0100 (MET)
Received: from [172.16.0.2] (helo=fillmore-labs.com)
	by fillmore.dyndns.org with esmtp (TLSv1:AES256-SHA:256)
	(Exim 4.30; FreeBSD)
	id 1AjGzo-000Km2-NH
	for FreeBSD-gnats-submit@FreeBSD.org; Wed, 21 Jan 2004 12:58:08 +0100
Message-Id: <400E694E.3000405@fillmore-labs.com>
Date: Wed, 21 Jan 2004 12:58:06 +0100
From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: make(1) word splitting swallows quotes

>Number:         61673
>Category:       bin
>Synopsis:       make(1) word splitting swallows quotes
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 21 04:00:31 PST 2004
>Closed-Date:    Mon Feb 23 04:12:06 PST 2004
>Last-Modified:  Mon Feb 23 04:12:06 PST 2004
>Originator:     Oliver Eikemeier
>Release:        FreeBSD 4.9-STABLE i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com
>Environment:
System: FreeBSD nuuk.fillmore-labs.com 4.9-STABLE

>Description:

Make reduces two (empty) quotes to one if they are not the first word
in a string. This work with :S, :C, :M and others and is true for double
and single quotes.

>How-To-Repeat:

* Makefile:

QUOTETEST1=	""
QUOTETEST2=	"" ab
QUOTETEST3=	ab ""
QUOTETEST4=	ab "" cd
QUOTETEST5=	ab "" "cd  - ef" "" jk

all:
	@echo 'QUOTETEST1: ${QUOTETEST1:M*}'
	@echo 'QUOTETEST2: ${QUOTETEST2:M*}'
	@echo 'QUOTETEST3: ${QUOTETEST3:M*}'
	@echo 'QUOTETEST4: ${QUOTETEST4:M*}'
	@echo 'QUOTETEST5a: ${QUOTETEST5:S/^/</:S/$/>/}'
	@echo 'QUOTETEST5b: ${QUOTETEST5:S/$/>/:S/^/</}'

* Result:

QUOTETEST1: ""
QUOTETEST2: "" ab
QUOTETEST3: ab "
QUOTETEST4: ab " cd
QUOTETEST5a: <ab> <" <"cd> -> ef" <"> <jk>
QUOTETEST5b: <ab> <"> "cd <- <ef"> "> <jk>

* Expected result:

QUOTETEST1: ""
QUOTETEST2: "" ab
QUOTETEST3: ab ""
QUOTETEST4: ab "" cd
QUOTETEST5a: <ab> <""> <"cd - ef"> <""> <jk>
QUOTETEST5b: <ab> <""> <"cd - ef"> <""> <jk>

>Fix:

It looks like brk_string in src/usr.bin/make/str.c is responsible for that:

inquote = '\0';
for (p = str, start = t = buffer;; ++p) {
	switch(ch = *p) {
	case '"':
	case '\'':
		if (inquote) {
			if (inquote == ch)
				inquote = '\0';
			else
				break;
		} else {
			inquote = (char) ch;
			/* Don't miss "" or '' */
			if (start == NULL && p[1] == inquote) {
				start = t + 1;
				break;
			}
		}
		if (!expand) {
			if (!start)
				start = t;
			*t++ = ch;
		}
		continue;
	[...]
	}
	if (!start)
		start = t;
	*t++ = (char) ch;
}

Essentially the part after /* Don't miss "" or '' */.
Maybe something like this will do the trick:

inquote = '\0';
start = (char *)NULL;
for (p = str, t = buffer;; ++p) {
	switch(ch = *p) {
	case '"':
	case '\'':
		if (inquote) {
			if (inquote == ch)
				inquote = '\0';
			else
				break;
		} else {
			inquote = (char) ch;
		}
		if (!expand) {
			if (!start)
				start = t;
			*t++ = ch;
		}
		continue;
	[...]
	}
	if (!start)
		start = t;
	*t++ = (char) ch;
}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: ru 
Responsible-Changed-When: Wed Jan 21 06:12:57 PST 2004 
Responsible-Changed-Why:  
Assign to myself. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61673 
State-Changed-From-To: open->patched 
State-Changed-By: ru 
State-Changed-When: Thu Jan 22 10:18:07 PST 2004 
State-Changed-Why:  
Fixed in make/str.c,v 1.28 in 5.2-CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61673 
State-Changed-From-To: patched->closed 
State-Changed-By: ru 
State-Changed-When: Mon Feb 23 04:11:23 PST 2004 
State-Changed-Why:  
Fixed in make/str.c,v 1.12.2.2 in 4.9-STABLE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=61673 
>Unformatted:
