NetBSD Problem Report #52159

From www@NetBSD.org  Thu Apr 13 02:42:32 2017
Return-Path: <www@NetBSD.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 "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 0C4B77A278
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 13 Apr 2017 02:42:32 +0000 (UTC)
Message-Id: <20170413024230.41E6B7A2AF@mollari.NetBSD.org>
Date: Thu, 13 Apr 2017 02:42:30 +0000 (UTC)
From: jamie@catflap.org
Reply-To: jamie@catflap.org
To: gnats-bugs@NetBSD.org
Subject: bmake(1) - SIGSEGV attempting to read unassigned Path (i.e. NULL pointer)
X-Send-Pr-Version: www-1.0

>Number:         52159
>Category:       bin
>Synopsis:       bmake(1) - SIGSEGV attempting to read unassigned Path (i.e. NULL pointer)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Apr 13 02:45:00 +0000 2017
>Closed-Date:    Wed Jan 17 00:06:04 +0000 2018
>Last-Modified:  Wed Jan 17 00:06:04 +0000 2018
>Originator:     Jamie Landeg-Jones
>Release:        head
>Organization:
n/a
>Environment:
NetBSD norge 7.0.1_PATCH NetBSD 7.0.1_PATCH (GENERIC.201607220540Z) amd64
>Description:
** NOTE: I use FreeBSD, but I confirmed the problem occurs with the sdf.org public access NetBSD system, and confirmed via your cvsweb that the version I'm running is the same version as your current.

> FreeBSD lapcat.dyslexicfish.net 11.0-STABLE FreeBSD 11.0-STABLE #0: Thu Dec  8 02:44:51 GMT 2016     root@lapcat.dyslexicfish.net:/usr/obj/usr/src/sys/LAPCAT  amd64

(I also synced my FreeBSD version to HEAD before reporting)

Basically, make SIGSEGVs when a directory path contains a "$" character. Yeah, I know, I know, but it's still a legal character, and I found this in the "real world" not by looking for bugs.
>How-To-Repeat:
> mkdir '$$'
> cd '$$'
> make
Segmentation fault (core dumped)
>Fix:
Something is causing the value (struct Path) for "dot" to be unassigned when a dollar exists in the pathame, in the function "Dir_Expand" (dir.c)

When this functions calls DirMatchFiles on this entry, it therefore sigsevs.

This is higlighted with the following assert patch:

03:39 (62) "$kdjd" root@lapcat# diff -u /usr/src/contrib/bmake/dir.c.orig /usr/src/contrib/bmake/dir.c
--- /usr/src/contrib/bmake/dir.c.orig   2017-04-12 20:08:13.000000000 +0100
+++ /usr/src/contrib/bmake/dir.c        2017-04-13 02:57:26.688274000 +0100
@@ -141,6 +141,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <stdio.h>
+#include <assert.h>

 #include "make.h"
 #include "hash.h"
@@ -911,6 +912,7 @@
            /*
             * First the files in dot
             */
+           assert (dot != NULL);
            DirMatchFiles(word, dot, expansions);

            /*

...

*134* 03:41 (68) "$kdjd" root@lapcat# pwd
/usr/src/usr.bin/bmake/xx/$kdjd
03:41 (69) "$kdjd" root@lapcat# ../../make
Assertion failed: (dot != NULL), function Dir_Expand, file /usr/src/contrib/bmake/dir.c, line 915.
Abort (core dumped)


>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/52159 CVS commit: src/usr.bin/make
Date: Thu, 13 Apr 2017 09:55:23 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Thu Apr 13 13:55:23 UTC 2017

 Modified Files:
 	src/usr.bin/make: main.c

 Log Message:
 PR/52159: Jamie Landeg-Jones: Don't try to expand $'s in paths or system
 variables. Only expand them ${MAKE} variable values.


 To generate a diff of this commit:
 cvs rdiff -u -r1.259 -r1.260 src/usr.bin/make/main.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Wed, 17 Jan 2018 00:06:04 +0000
State-Changed-Why:
Fixed by christos, thanks for the report.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.