NetBSD Problem Report #54574
From buhrow@lothlorien.nfbcal.org Thu Sep 26 02:52:59 2019
Return-Path: <buhrow@lothlorien.nfbcal.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 36AC77A178
for <gnats-bugs@www.NetBSD.org>; Thu, 26 Sep 2019 02:52:59 +0000 (UTC)
Message-Id: <201909260252.x8Q2qu7o023183@lothlorien.nfbcal.org>
Date: Wed, 25 Sep 2019 19:52:56 -0700 (PDT)
From: buhrow@nfbcal.org
Reply-To: buhrow@nfbcal.org
To: gnats-bugs@www.NetBSD.org
Subject: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
X-Send-Pr-Version: 3.95
>Number: 54574
>Category: toolchain
>Synopsis: usr.bin/make/parse.c $Id: 1.231 drops core in realpath(3) on NetBSD-5.2
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: sjg
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Sep 26 02:55:00 +0000 2019
>Closed-Date: Tue Apr 21 19:50:20 +0000 2020
>Last-Modified: Tue Apr 21 19:50:20 +0000 2020
>Originator: Brian Buhrow
>Release: NetBSD 5.2_STABLE
>Organization:
NFB of California
>Environment:
System: NetBSD lothlorien.nfbcal.org 5.2_STABLE NetBSD 5.2_STABLE (RBL) #0: Thu Mar 27 10:15:56 PDT 2014 buhrow@lothlorien.nfbcal.org:/usr/src/sys/arch/i386/compile/RBL i386
Architecture: i386
Machine: i386
>Description:
When trying to build NetBSD-9 release on a NetBSD-5.2 system using sources
from the netbsd-9 branch, nbmake core dumps when realpath is called from
usr.bin/make/parse.c. It appears the changes sjg made in Revision 1.231 of
parse.c are the culprit. Using versions of parse.c older than 1.231 run
without trouble on NetBSD-5.2.
>How-To-Repeat:
Download the src-90 source tree on a NetBSD-5.2 system.
Clear your obj directory.
Then run:
./build.sh -m amd64 -D /var/tmp/netbsd-90-64 -O /usr/local/netbsd/obj-64 -j 4 release
>Fix:
Figure out why realpath is seg faulting with the pointers given it by
parse.c as added in parse.c, 1.231.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: bin-bug-people->sjg
Responsible-Changed-By: jnemeth@NetBSD.org
Responsible-Changed-When: Thu, 26 Sep 2019 05:25:25 +0000
Responsible-Changed-Why:
Over to committer.
State-Changed-From-To: open->analyzed
State-Changed-By: jnemeth@NetBSD.org
State-Changed-When: Thu, 26 Sep 2019 05:25:25 +0000
State-Changed-Why:
I analyzed it.
From: John Nemeth <jnemeth@cue.bc.ca>
To: gnats-bugs@netbsd.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc:
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Wed, 25 Sep 2019 22:22:05 -0700
On Sep 26, 2:55am, buhrow@nfbcal.org wrote:
}
} >Number: 54574
} >Category: bin
} >Synopsis: usr.bin/make/parse.c $Id: 1.231 drops core in realpath(3) on NetBSD-5.2
} >Arrival-Date: Thu Sep 26 02:55:00 +0000 2019
} >Originator: Brian Buhrow
} >Release: NetBSD 5.2_STABLE
} >Organization:
} NFB of California
}
} >Environment:
}
}
} System: NetBSD lothlorien.nfbcal.org 5.2_STABLE NetBSD 5.2_STABLE (RBL) #0: Thu Mar 27 10:15:56 PDT 2014 buhrow@lothlorien.nfbcal.org:/usr/src/sys/arch/i386/compile/RBL i386
} Architecture: i386
} Machine: i386
} >Description:
} When trying to build NetBSD-9 release on a NetBSD-5.2 system using sources
} from the netbsd-9 branch, nbmake core dumps when realpath is called from
} usr.bin/make/parse.c. It appears the changes sjg made in Revision 1.231 of
} parse.c are the culprit. Using versions of parse.c older than 1.231 run
} without trouble on NetBSD-5.2.
}
} >How-To-Repeat:
}
} Download the src-90 source tree on a NetBSD-5.2 system.
} Clear your obj directory.
} Then run:
}
} ./build.sh -m amd64 -D /var/tmp/netbsd-90-64 -O /usr/local/netbsd/obj-64 -j 4 release
} >Fix:
} Figure out why realpath is seg faulting with the pointers given it by
} parse.c as added in parse.c, 1.231.
}
} >Unformatted:
The manpage for realpath(3) says:
HISTORY
The realpath() function call first appeared in 4.4BSD. In NetBSD 7.0 the
function was updated to accept a NULL pointer for the resolvedname
argument.
POSIX says:
If resolved_name is a null pointer, the behavior of realpath() is
implementation-defined.
parse.c:1.231 in ParseVErrorInternal() calls realpath() with a null
pointer for resolved_name thus relying on the NetBSD 7.0 behaviour.
This is a portability bug.
}-- End of excerpt from buhrow@nfbcal.org
From: "Simon J. Gerraty" <sjg@juniper.net>
To: <gnats-bugs@netbsd.org>
Cc: <gnats-admin@netbsd.org>, <netbsd-bugs@netbsd.org>, <buhrow@nfbcal.org>,
<sjg@juniper.net>
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Wed, 25 Sep 2019 23:21:02 -0700
John Nemeth <jnemeth@cue.bc.ca> wrote:
> HISTORY
> The realpath() function call first appeared in 4.4BSD. In NetBSD =
7.0 the
> function was updated to accept a NULL pointer for the resolvedname
> argument.
> =
> POSIX says:
> =
> If resolved_name is a null pointer, the behavior of realpath() is
> implementation-defined.
> =
> parse.c:1.231 in ParseVErrorInternal() calls realpath() with a null
> pointer for resolved_name thus relying on the NetBSD 7.0 behaviour.
> This is a portability bug.
Thanks, will fix
From: "Simon J. Gerraty" <sjg@juniper.net>
To: <gnats-bugs@netbsd.org>
Cc: <gnats-admin@netbsd.org>, <netbsd-bugs@netbsd.org>, <buhrow@nfbcal.org>,
<sjg@juniper.net>
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Wed, 25 Sep 2019 23:35:32 -0700
John Nemeth <jnemeth@cue.bc.ca> wrote:
> The realpath() function call first appeared in 4.4BSD. In NetBSD =
7.0 the
> function was updated to accept a NULL pointer for the resolvedname
> argument.
> =
> POSIX says:
> =
> If resolved_name is a null pointer, the behavior of realpath() is
> implementation-defined.
> =
> parse.c:1.231 in ParseVErrorInternal() calls realpath() with a null
> pointer for resolved_name thus relying on the NetBSD 7.0 behaviour.
> This is a portability bug.
The following should be safe:
Index: parse.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.232
diff -u -p -r1.232 parse.c
--- parse.c 9 Apr 2019 18:28:10 -0000 1.232
+++ parse.c 26 Sep 2019 06:31:44 -0000
@@ -669,6 +669,7 @@ static void
ParseVErrorInternal(FILE *f, const char *cfname, size_t clineno, int type=
,
const char *fmt, va_list ap)
{
static Boolean fatal_warning_error_printed =3D FALSE;
+ char dirbuf[MAXPATHLEN+1];
=
(void)fprintf(f, "%s: ", progname);
@@ -688,7 +689,7 @@ ParseVErrorInternal(FILE *f, const char =
if (dir =3D=3D NULL)
dir =3D ".";
if (*dir !=3D '/') {
- dir =3D cp2 =3D realpath(dir, NULL);
+ dir =3D cp2 =3D realpath(dir, dirbuf);
free(cp);
cp =3D cp2; /* cp2 set to NULL by Var_Value */
}
From: Brian Buhrow <buhrow@nfbcal.org>
To: gnats-bugs@netbsd.org, sjg@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org
Cc: buhrow@nfbcal.org
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 11:53:29 -0700
hello Simon. Unfortunately, your patch doesn't fix the problem.
After your patch, nbmake (make) core dumps when it calls vfprint() in the
same function.
Further testing shows that parse.c, versions up to 1.230 work fine, but versions
1.231 and 1.232 fail. I tried looking at the failure after your patch, but
couldn't figure out why the call to vfprint failed since it looks like that
call exists before your patches went into the file. I think it has
something to do with the cp variable, but I didn't have time to look
further into it.
If you want me to try a different patch, let me know.
-thanks
-Brian
From: "Simon J. Gerraty" <sjg@juniper.net>
To: <gnats-bugs@netbsd.org>
Cc: <gnats-admin@netbsd.org>, <netbsd-bugs@netbsd.org>, <buhrow@nfbcal.org>,
<sjg@juniper.net>
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 12:07:28 -0700
Hi Brian
> hello Simon. Unfortunately, your patch doesn't fix the problem.
> After your patch, nbmake (make) core dumps when it calls vfprint() in t=
he
> same function.
> Further testing shows that parse.c, versions up to 1.230 work fine, but=
versions
> 1.231 and 1.232 fail. I tried looking at the failure after your patch,=
but
> couldn't figure out why the call to vfprint failed since it looks like =
that
> call exists before your patches went into the file. I think it has
> something to do with the cp variable, but I didn't have time to look
> further into it.
It would be handy if you could provide stack trace from core file.
> If you want me to try a different patch, let me know.
Thanks, hopefully once I see the stack trace...
From: "Simon J. Gerraty" <sjg@juniper.net>
To: Brian Buhrow <buhrow@nfbcal.org>
Cc: <gnats-bugs@netbsd.org>, <gnats-admin@netbsd.org>,
<netbsd-bugs@netbsd.org>, <sjg@juniper.net>
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 12:57:53 -0700
Brian Buhrow <buhrow@nfbcal.org> wrote:
> hello. Here is the stack trace. I don't have debugging symbols in
> the binaries, but this should give you an idea.
> Let me know if you need anything else.
Thanks.
Odd. By the time vfprintf is called we are already done with reporting
the makefile path.
Oh never mind, we should not be attempting to free return from realpath.
Can you please try the patch below.
Index: parse.c
===================================================================
RCS file: /cvsroot/src/usr.bin/make/parse.c,v
retrieving revision 1.232
diff -u -p -r1.232 parse.c
--- parse.c 9 Apr 2019 18:28:10 -0000 1.232
+++ parse.c 26 Sep 2019 19:55:44 -0000
@@ -670,6 +670,7 @@ ParseVErrorInternal(FILE *f, const char
const char *fmt, va_list ap)
{
static Boolean fatal_warning_error_printed = FALSE;
+ char dirbuf[MAXPATHLEN+1];
(void)fprintf(f, "%s: ", progname);
@@ -688,9 +689,7 @@ ParseVErrorInternal(FILE *f, const char
if (dir == NULL)
dir = ".";
if (*dir != '/') {
- dir = cp2 = realpath(dir, NULL);
- free(cp);
- cp = cp2; /* cp2 set to NULL by Var_Value */
+ dir = realpath(dir, dirbuf);
}
fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2);
if (fname == NULL) {
From: Brian Buhrow <buhrow@nfbcal.org>
To: "Simon J. Gerraty" <sjg@juniper.net>, <gnats-bugs@netbsd.org>
Cc: <gnats-admin@netbsd.org>, <netbsd-bugs@netbsd.org>, buhrow@nfbcal.org
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 12:21:27 -0700
hello. Here is the stack trace. I don't have debugging symbols in
the binaries, but this should give you an idea.
Let me know if you need anything else.
-thanks
-Brian
Script started on Thu Sep 26 12:16:41 2019
lothlorien# gdb nbmake
GNU gdb 6.5
Copyright (C) 2006 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--netbsdelf"...(no debugging symbols found)
(gdb) core /var/tmp/nbmake.core
Reading symbols from /usr/lib/libc.so.12...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libc.so.12
Reading symbols from /usr/libexec/ld.elf_so...(no debugging symbols found)...done.
Loaded symbols for /usr/libexec/ld.elf_so
Core was generated by `nbmake'.
Program terminated with signal 11, Segmentation fault.
#0 0xbbba2397 in __vfprintf_unlocked () from /usr/lib/libc.so.12
(gdb) bt
#0 0xbbba2397 in __vfprintf_unlocked () from /usr/lib/libc.so.12
#1 0xbbba2f46 in __vfprintf_unlocked () from /usr/lib/libc.so.12
#2 0xbbba5e33 in vfprintf () from /usr/lib/libc.so.12
#3 0x080583a5 in ParseVErrorInternal ()
#4 0x02080584 in ?? ()
#5 0x26000000 in ?? ()
#6 0xa8080644 in ?? ()
#7 0xd0bfbfd4 in ?? ()
#8 0x00bbbd3b in ?? ()
#9 0x34bb95c9 in ?? ()
---Type <return> to continue, or q <return> to quit---
#10 0x98bbaf21 in ?? ()
#11 0xefbfbfd4 in ?? ()
#12 0x36bbb720 in ?? ()
#13 0x34bbaf21 in ?? ()
#14 0xa8bbaf21 in ?? ()
#15 0x00bfbfd4 in ?? ()
#16 0x36bb95c9 in ?? ()
#17 0x34bbaf21 in ?? ()
#18 0xd8bbaf21 in ?? ()
#19 0x0ebfbfd4 in ?? ()
---Type <return> to continue, or q <return> to quit---
#20 0x02080593 in ?? ()
#21 0x26000000 in ?? ()
#22 0x00080644 in ?? ()
#23 0x03bb95c8 in ?? ()
#24 0x34000000 in ?? ()
#25 0x00bbaf21 in ?? ()
#26 0x01bb95c8 in ?? ()
#27 0x01000000 in ?? ()
#28 0x14000000 in ?? ()
#29 0x00210653 in ?? ()
---Type <return> to continue, or q <return> to quit---
#30 0x26000000 in ?? ()
#31 0x2c080644 in ?? ()
#32 0x2dbbaf21 in ?? ()
#33 0x9ebbaf21 in ?? ()
#34 0x28080654 in ?? ()
#35 0x07bfbfd5 in ?? ()
#36 0x2c080598 in ?? ()
#37 0xf0bbaf21 in ?? ()
#38 0x28bb9010 in ?? ()
#39 0xf6bfbfd5 in ?? ()
---Type <return> to continue, or q <return> to quit---
#40 0x2c080597 in ?? ()
#41 0x01bbaf21 in ?? ()
#42 0x00bbbce7 in ?? ()
#43 0x00000001 in ?? ()
#44 0x24000000 in ?? ()
#45 0x003a90a4 in ?? ()
#46 0xa0000000 in ?? ()
#47 0x52bb9600 in ?? ()
#48 0x20000000 in ?? ()
#49 0x01bb90a4 in ?? ()
---Type <return> to continue, or q <return> to quit---
#50 0xc5000000 in ?? ()
#51 0x69bb9600 in ?? ()
#52 0x03bb90a4 in ?? ()
#53 0x5b000000 in ?? ()
#54 0x58080633 in ?? ()
#55 0x94bfbfd5 in ?? ()
#56 0x69080549 in ?? ()
#57 0x03bb90a4 in ?? ()
#58 0x80000000 in ?? ()
#59 0x00bb9010 in ?? ()
---Type <return> to continue, or q <return> to quit---
#60 0x10000000 in ?? ()
#61 0x80000000 in ?? ()
#62 0x00bb9044 in ?? ()
#63 0x50bb90b8 in ?? ()
#64 0x40bb9305 in ?? ()
#65 0x50bb9305 in ?? ()
#66 0x88080547 in ?? ()
#67 0x9cbfbfd5 in ?? ()
#68 0x6908052b in ?? ()
#69 0x00bb90a4 in ?? ()
---Type <return> to continue, or q <return> to quit---
#70 0x88000000 in ?? ()
#71 0x25bfbfd5 in ?? ()
#72 0x00bbb1a8 in ?? ()
#73 0x24000000 in ?? ()
#74 0xa8080645 in ?? ()
#75 0x80bbbd70 in ?? ()
#76 0xd5bb9044 in ?? ()
#77 0x01080644 in ?? ()
#78 0xb8080674 in ?? ()
#79 0x69bfbfd5 in ?? ()
---Type <return> to continue, or q <return> to quit---
#80 0x8008052b in ?? ()
#81 0x40bb9044 in ?? ()
#82 0x00bb9305 in ?? ()
#83 0x50000000 in ?? ()
#84 0x80080547 in ?? ()
#85 0x00bb9044 in ?? ()
#86 0x00000000 in ?? ()
(gdb) quit
lothlorien# exit
lothlorien# exit
Script done on Thu Sep 26 12:17:12 2019
From: Brian Buhrow <buhrow@nfbcal.org>
To: "Simon J. Gerraty" <sjg@juniper.net>
Cc: <gnats-bugs@netbsd.org>, <gnats-admin@netbsd.org>,
<netbsd-bugs@netbsd.org>, buhrow@nfbcal.org
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 13:59:21 -0700
Hello Simon. The latest patch, V1.232 + your latest patch, works just
fine. I think you can commit that. Or, if you want, I can commit it.
-thanks
-Brian
On Sep 26, 12:57pm, "Simon J. Gerraty" wrote:
} Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetB
} Brian Buhrow <buhrow@nfbcal.org> wrote:
}
} > hello. Here is the stack trace. I don't have debugging symbols in
} > the binaries, but this should give you an idea.
} > Let me know if you need anything else.
}
} Thanks.
} Odd. By the time vfprintf is called we are already done with reporting
} the makefile path.
}
} Oh never mind, we should not be attempting to free return from realpath.
} Can you please try the patch below.
}
} Index: parse.c
} ===================================================================
} RCS file: /cvsroot/src/usr.bin/make/parse.c,v
} retrieving revision 1.232
} diff -u -p -r1.232 parse.c
} --- parse.c 9 Apr 2019 18:28:10 -0000 1.232
} +++ parse.c 26 Sep 2019 19:55:44 -0000
} @@ -670,6 +670,7 @@ ParseVErrorInternal(FILE *f, const char
} const char *fmt, va_list ap)
} {
} static Boolean fatal_warning_error_printed = FALSE;
} + char dirbuf[MAXPATHLEN+1];
}
} (void)fprintf(f, "%s: ", progname);
}
} @@ -688,9 +689,7 @@ ParseVErrorInternal(FILE *f, const char
} if (dir == NULL)
} dir = ".";
} if (*dir != '/') {
} - dir = cp2 = realpath(dir, NULL);
} - free(cp);
} - cp = cp2; /* cp2 set to NULL by Var_Value */
} + dir = realpath(dir, dirbuf);
} }
} fname = Var_Value(".PARSEFILE", VAR_GLOBAL, &cp2);
} if (fname == NULL) {
>-- End of excerpt from "Simon J. Gerraty"
From: Brian Buhrow <buhrow@nfbcal.org>
To: "Simon J. Gerraty" <sjg@juniper.net>
Cc: <gnats-bugs@netbsd.org>, <gnats-admin@netbsd.org>,
<netbsd-bugs@netbsd.org>, buhrow@nfbcal.org
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Thu, 26 Sep 2019 13:59:57 -0700
Hello. And, thank you for getting on this so quickly.
-Brian
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on
NetBSD-5.2 in realpath(3)
Date: Sat, 28 Sep 2019 16:24:12 +0000
On Thu, Sep 26, 2019 at 08:00:02PM +0000, Simon J. Gerraty wrote:
> {
> static Boolean fatal_warning_error_printed = FALSE;
> + char dirbuf[MAXPATHLEN+1];
nit: please use PATH_MAX (more portable) and it doesn't need +1 as it
is defined to include space for a null terminator.
(unless realpath is wrong...)
--
David A. Holland
dholland@netbsd.org
From: "Simon J. Gerraty" <sjg@juniper.net>
To: <gnats-bugs@netbsd.org>
Cc: <gnats-admin@netbsd.org>, <netbsd-bugs@netbsd.org>, <buhrow@nfbcal.org>,
<sjg@juniper.net>
Subject: Re: bin/54574: usr.bin/make/parse.c $Id: 1.231 drops core on NetBSD-5.2 in realpath(3)
Date: Mon, 30 Sep 2019 14:07:33 -0700
David Holland <dholland-bugs@netbsd.org> wrote:
> On Thu, Sep 26, 2019 at 08:00:02PM +0000, Simon J. Gerraty wrote:
> > {
> > static Boolean fatal_warning_error_printed = FALSE;
> > + char dirbuf[MAXPATHLEN+1];
>
> nit: please use PATH_MAX (more portable) and it doesn't need +1 as it
> is defined to include space for a null terminator.
FWIW I used MAXPATHLEN because that's what the rest of make is using.
The portability issue is probably somewhat moot for bmake
since make.h ensures both MAXPATHLEN and PATH_MAX are defined -
potentially in terms of BMAKE_PATH_MAX
Thanks
--sjg
State-Changed-From-To: analyzed->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Tue, 21 Apr 2020 19:50:20 +0000
State-Changed-Why:
confirmed fixed, thanks for the report :)
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.