From ltsampros@upnet.gr  Sun Jul  9 22:21:53 2006
Return-Path: <ltsampros@upnet.gr>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 23B9B16A4DA
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  9 Jul 2006 22:21:53 +0000 (UTC)
	(envelope-from ltsampros@upnet.gr)
Received: from mail.vivodinet.gr (mail6.vivodinet.gr [80.76.39.16])
	by mx1.FreeBSD.org (Postfix) with SMTP id 1297843D4C
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  9 Jul 2006 22:21:50 +0000 (GMT)
	(envelope-from ltsampros@upnet.gr)
Received: (qmail 1464 invoked from network); 9 Jul 2006 22:21:44 -0000
Received: from dsl-88-218-3-18.customers.vivodi.gr (HELO biftekaki.lan) (88.218.3.18)
  by 0 with SMTP; 9 Jul 2006 22:21:44 -0000
Received: from biftekaki.lan (localhost [127.0.0.1])
	by biftekaki.lan (8.13.6/8.13.6) with ESMTP id k69MJDQT007124
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 Jul 2006 01:19:14 +0300 (EEST)
	(envelope-from gaghiel@biftekaki.lan)
Received: (from gaghiel@localhost)
	by biftekaki.lan (8.13.6/8.13.6/Submit) id k69MJBgJ007123;
	Mon, 10 Jul 2006 01:19:11 +0300 (EEST)
	(envelope-from gaghiel)
Message-Id: <200607092219.k69MJBgJ007123@biftekaki.lan>
Date: Mon, 10 Jul 2006 01:19:11 +0300 (EEST)
From: Tsampros Leonidas <ltsampros@upnet.gr>
Reply-To: Tsampros Leonidas <ltsampros@upnet.gr>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: make crashes with invalid continuation lines
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         99985
>Category:       bin
>Synopsis:       [patch] make(1) crashes with invalid continuation lines
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 09 22:30:14 GMT 2006
>Closed-Date:    Mon Oct 16 11:48:41 GMT 2006
>Last-Modified:  Mon Oct 16 12:00:35 GMT 2006
>Originator:     Tsampros Leonidas
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
>Environment:
FreeBSD
System: FreeBSD biftekaki.lan 6.1-STABLE FreeBSD 6.1-STABLE #0: Sun Jul 2 17:23:11 UTC 2006 root@biftekaki.lan:/usr/obj/usr/src/sys/GENERIC i386

>Description:
	Make crashes with invalid continuation lines

>How-To-Repeat:
$ cat foo.c
int main(int argc, char *argv[]) {
        return 0;
}

$ cat koko.c
int number(int c);

int number(int c) {
        return c;
}

$ cat -nvte Makefile
     1  PROG=^Ifoo$
     2  $
     3  SRCS=^Ifoo.c \$
     4  ^Ikoko.c \ $
     5  $
     6  NO_MAN=^IYES$
     7  $
     8  .include <bsd.prog.mk>$

[gaghiel@biftekaki]make-bug $ make
Segmentation fault: 11 (core dumped)

$ gdb /usr/bin/make make.core
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-marcel-freebsd"...
Core was generated by `make'.
Program terminated with signal 11, Segmentation fault.
#0  0x08058c98 in brk_string (aa=0xbfbfd3d0, str=0x80caff0 "\\", expand=0) at /usr/src/usr.bin/make/str.c:262
262                                     *arg++ = str[0];
(gdb) bt
#0  0x08058c98 in brk_string (aa=0xbfbfd3d0, str=0x80caff0 "\\", expand=0) at /usr/src/usr.bin/make/str.c:262
#1  0x0805deab in VarModify (str=0x80c90d0 "\\", modProc=0x805caa8 <VarRoot>, datum=0x0) at /usr/src/usr.bin/make/var.c:1186
#2  0x0805ec72 in ParseModifier (vp=0xbfbfd570, startc=123 '{', v=0x80c9080, freeResult=0xbfbfd548) at /usr/src/usr.bin/make/var.c:1793
#3  0x0805ede9 in ParseRestModifier (vp=0xbfbfd570, startc=123 '{', buf=0x80c90c0, freeResult=0xbfbfd548) at /usr/src/usr.bin/make/var.c:1831
#4  0x0805f544 in VarParseLong (vp=0xbfbfd570, freeResult=0xbfbfd548) at /usr/src/usr.bin/make/var.c:2050
#5  0x0805f84f in VarParse (vp=0xbfbfd570, freeResult=0xbfbfd548) at /usr/src/usr.bin/make/var.c:2156
#6  0x0805fc8a in Var_SubstOnly (var=0x80c8a00 "_S", str=0x80c8b00 "${_S:R}.o: ${_S}\n", err=0) at /usr/src/usr.bin/make/var.c:2426
#7  0x0804d49c in For_Run (lineno=76) at /usr/src/usr.bin/make/for.c:274
#8  0x08057434 in parse_for (line=0x80c8f00 "\\", code=0, lineno=76) at /usr/src/usr.bin/make/parse.c:2279
#9  0x080575a4 in parse_directive (line=0x80c8901 "for _S in ${SRCS:N*.[hly]}") at /usr/src/usr.bin/make/parse.c:2335
#10 0x08057614 in Parse_File (name=0x80a8340 "Makefile", stream=0x8095120) at /usr/src/usr.bin/make/parse.c:2367
#11 0x08052c3b in ReadMakefile (p=0x8087e27 "Makefile") at /usr/src/usr.bin/make/main.c:312
#12 0x08053e2b in main (argc=1, argv=0xbfbfe83c) at /usr/src/usr.bin/make/main.c:971

>Fix:

>Release-Note:
>Audit-Trail:

From: Nate Eldredge <nge@cs.hmc.edu>
To: bug-followup@FreeBSD.org, ltsampros@upnet.gr
Cc:  
Subject: Re: bin/99985: make(1) crashes with invalid continuation lines
Date: Tue, 1 Aug 2006 18:49:49 -0700 (PDT)

 Well, here is a patch which fixes this bug.  Though I'm a little confused 
 as to the behavior of the code anyway.
 
 In brk_string in str.c, if expand == 0, a backslash causes itself and the 
 following character to be copied to the output, without processing.  If 
 the following character is the terminating null, then it won't be noticed, 
 and we'll march happily beyond the end of the string (and maybe crash, or 
 maybe not).  So this patch fixes that.  However, the behavior seems odd in 
 general.  For instance, as it stands the string "foo\ bar" is a single 
 argument, whereas "foo/ bar" is two args:  {"foo/", "bar"}.  I don't 
 understand what the correct semantics should be.
 
 Note the bug has been present since revision 1.3, which apparently was 
 imported from NetBSD for FreeBSD 2.0.5, back in 1995.  In May 2005 we 
 imported a version from DragonFlyBSD by Max Okumoto, who largely rewrote 
 the function, keeping the bug intact!
 
 --- /usr/src/usr.bin/make/str.c	Mon May 23 06:27:52 2005
 +++ str.c	Tue Aug  1 18:25:34 2006
 @@ -260,8 +260,14 @@
   				}
   			} else {
   				*arg++ = str[0];
 -				++str;
 -				*arg++ = str[0];
 +				/* 
 +				 * FIXME: Why does a backslash protect
 +				 * the next character even with expand=0 ?
 +				 */
 +				if (str[1]) {
 +					++str;
 +					*arg++ = str[0];
 +				}
   			}
   			break;
   		default:
 
 -- 
 Nate Eldredge
 nge@cs.hmc.edu
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: ru 
Responsible-Changed-When: Sun Oct 8 00:15:24 UTC 2006 
Responsible-Changed-Why:  
Grab the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99985 
State-Changed-From-To: open->patched 
State-Changed-By: ru 
State-Changed-When: Mon Oct 9 19:38:28 UTC 2006 
State-Changed-Why:  
Fix committed, thanks.  I didn't change the historical behavior 
of `\' to prevent treating whitespace as a separator -- all BSD 
make's behave like this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99985 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/99985: commit references a PR
Date: Mon,  9 Oct 2006 19:37:49 +0000 (UTC)

 ru          2006-10-09 19:37:26 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/make         str.c 
   Log:
   Don't go beyond the provided string when parsing the `\' character.
   
   PR:             bin/99985
   Submitted by:   Nate Eldredge
   MFC after:      3 days
   
   Revision  Changes    Path
   1.46      +4 -2      src/usr.bin/make/str.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: ru 
State-Changed-When: Mon Oct 16 11:48:10 UTC 2006 
State-Changed-Why:  
Fix merged into RELENG_6. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99985 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/99985: commit references a PR
Date: Mon, 16 Oct 2006 11:51:34 +0000 (UTC)

 ru          2006-10-16 11:51:18 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/make         str.c 
   Log:
   MFC: 1.46: Don't go beyond the provided string when parsing `\'.
   
   PR:             bin/99985
   Approved by:    re (hrs)
   
   Revision  Changes    Path
   1.45.2.1  +4 -2      src/usr.bin/make/str.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
