Bug 190100

Summary: [patch] make(1): fix core dumps at syntax error
Product: Base System Reporter: lampa
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Open ---    
Severity: Affects Only Me Keywords: patch
Priority: Normal    
Version: 9.2-STABLE   
Hardware: Any   
OS: Any   

Description lampa 2014-05-22 11:10:00 UTC
make core dumps with this invalid Makefile (notice two && operators):

OSVERSION=901500
. if ${OSVERSION} >= 901500 && && (${ARCH} == i386 || ${ARCH} == amd64)
. endif

(gdb) where
#0  0x0000000000448d8c in kill ()
#1  0x0000000000447bd8 in abort ()
#2  0x0000000000403197 in Cond_If (
    line=0x80085de05 "${OSVERSION} >= 901500 && && (${ARCH} == i386 || ${ARCH} == amd64)", code=<value optimized out>, lineno=2)
    at /usr/src/usr.bin/make/cond.c:1079
#3  0x000000000040d64c in Parse_File (name=<value optimized out>,
    stream=<value optimized out>) at /usr/src/usr.bin/make/parse.c:2366
#4  0x000000000040a274 in ReadMakefile (p=<value optimized out>)
    at /usr/src/usr.bin/make/main.c:323
#5  0x000000000040a328 in TryReadMakefile (p=0x80081a1b0 "Makefile")
    at /usr/src/usr.bin/make/main.c:342
#6  0x000000000040a879 in main (argc=3, argv=0x7fffffffea90)
    at /usr/src/usr.bin/make/main.c:1185

It seems that current token from CondE(TRUE) is And and this is not handled correctly in switch() at line 1061. Perhaps any unexpected token can be here?

Fix: 

remove default: block and change case Err: to default:

      switch (CondE(TRUE)) {
          case True:
                if (CondToken(TRUE) != EndOfFile)
                        goto err;
                value = TRUE;
                break;

          case False:
                if (CondToken(TRUE) != EndOfFile)
                        goto err;
                value = FALSE;
                break;

          default:
  err:          Parse_Error(PARSE_FATAL, "Malformed conditional (%s)", line);
                return;

        }

With this change it correctly reports:

"Makefile", line 2: Malformed conditional ...
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:26 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped
Comment 2 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:40:59 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>