[comp.bugs.4bsd] bin/make dereferences a NULL pointer if VPATH is not defined. +Fix

gww@marduk.UUCP (Gary Winiger) (09/05/87)

Subject: bin/make dereferences a NULL pointer if VPATH is not defined. +Fix
Index:	 bin/make/files.c 4.3BSD +Fix

Description:
	If the macro VPATH is not defined in the Makefile, make attempts
	to determine this by dereferencing a NULL pointer.  On certain
	systems this will cause a segmentation fault.
Repeat-By:
	Running make against a Makefile without VPATH defined on a system
	that will not allow NULL pointer dereferencing.
Fix:
	Check to see if the pointer is NULL before dereferencing it.
	The attached fix resolves this problem at our site.

Gary..
{ucbvax!sun,lll-lcc!lll-tis,amdahl!altos86,bridge2}!elxsi!gww
--------- cut --------- snip --------- :.,$w diff -------------
*** /tmp/,RCSt1000523	Fri Dec 12 17:30:39 1986
--- /usr/src/bin/make/files.c	Fri Dec 12 17:28:15 1986
***************
*** 1,10 ****
  /*
   * $Log:	files.c,v $
   * Revision 1.1  86/12/11  12:53:15  gww
   * Initial revision
   * 
   */
! static char *ERcsId = "$Header: files.c,v 1.1 86/12/11 12:53:15 gww Exp $ ENIX BSD";
  static	char *sccsid = "@(#)files.c	4.12 (Berkeley) 86/01/09";
  #include <fcntl.h>
  
--- 1,17 ----
  /*
   * $Log:	files.c,v $
+  * Revision 1.2  86/12/12  17:27:34  gww
+  * Don't dereference null pointer when VPATH is not defined.
+  * 
   * Revision 1.1  86/12/11  12:53:15  gww
   * Initial revision
   * 
   */
! static char *ERcsId = "$Header: files.c,v 1.2 86/12/12 17:27:34 gww Exp $ ENIX BSD";
  static	char *sccsid = "@(#)files.c	4.12 (Berkeley) 86/01/09";
  #include <fcntl.h>
  
***************
*** 230,236 ****
  	dirpref = "";
  	filepat = pat;
  	cp = varptr("VPATH");
! 	if (*cp->varval == 0) path = ".";
  	else {
  	       path = pth; 
  	       *path = '\0';
--- 237,243 ----
  	dirpref = "";
  	filepat = pat;
  	cp = varptr("VPATH");
! 	if (cp->varval == NULL || *cp->varval == 0) path = ".";
  	else {
  	       path = pth; 
  	       *path = '\0';