[net.bugs.usg] Make bug

dt@ist.UUCP (David Tilbrook) (01/29/85)

I recently found the following bug (feature?) in System 3, 5, OSx Make
in the following shell script:

cat <<'!' >make.tmp
MAIN:
	echo *
!
make -f make.tmp
make -f - <make.tmp

The outputs on all my systems (4.1, SysV, OSx) in empty directories were:

echo *
make.tmp
echo *
*

Is this an obscure and useful feature the value of which I
fail to understand or appreciate?
-- 
David Tilbrook		{inset, root44, mcvax, qtlon}!ist!dt
Imperial Software Technology, London England

wescott@ncrcae.UUCP (Mike Wescott) (02/06/85)

David Tilbrook, Imperial Software Technology, London England in <305@ist.UUCP>
points up a bug in make whereby the shell's filename  expansion is suppressed
when make is invoked:

	make -f - < descfile

rather than:

	make -f descfile

The bug is actually in /bin/sh.  In sh/expand.c around line 112 the shell
attemps to open a directory to scan for file name expansions:

	if ((dirf = open(*s ? s : ".", 0)) > 0)
	{
		if (fstat(dirf, &statb) != -1 &&
		    (statb.st_mode & S_IFMT) == S_IFDIR)
			dir++;
		else
			close(dirf);
	} 

The asuumption is that open will never return 0; the check should be >= 0.

How is it that stdin is not open?  In make, in main.c while parsing the
-f flag, the routine rddescf() is called.  rddescf() fopen's the file named
by the argument following the -f flag unless it is "-".  The file pointer
retruned by fopen or stdin is then passed to rdd1() which reads and fcloses
the file passed to it; hence when "-f -" is used stdin is closed before
/bin/sh is called.  This is also a bug since

	make -f - -f -

won't work properly, but then it's kinda silly anyway.

Mike Wescott
NCR Corp.
mcnc!ncsu!ncrcae!wescott
akgua!usceast!ncrcae!wescott

ed@mtxinu.UUCP (Ed Gould) (02/12/85)

> I recently found the following bug (feature?) in System 3, 5, OSx Make
> in the following shell script:
> 
> cat <<'!' >make.tmp
> MAIN:
> 	echo *
> !
> make -f make.tmp
> make -f - <make.tmp
> 
> The outputs on all my systems (4.1, SysV, OSx) in empty directories were:
> 
> echo *
> make.tmp
> echo *
> *
> 
> Is this an obscure and useful feature the value of which I
> fail to understand or appreciate?
> -- 
> David Tilbrook		{inset, root44, mcvax, qtlon}!ist!dt
> Imperial Software Technology, London England

I get the following on 4.2bsd, using the 4.2 make and also Doug Gwyn's
System V make (/usr/5bin/make).  Note that since I generated this
with "script" the file "typescript" also appears.  (Editing to change
the ../xx file is omitted.)

	(ed) mtxinu> cat ../xx
	cat <<'!' >make.tmp
	MAIN:
		echo *
	!
	make -f make.tmp
	make -f - <make.tmp
	(ed) mtxinu> /bin/sh ../xx
	echo *
	make.tmp typescript
	echo *
	make.tmp typescript
	(ed) mtxinu> cat ../xx
	cat <<'!' >make.tmp
	MAIN:
		echo *
	!
	/usr/5bin/make SHELL=/bin/sh -f make.tmp
	/usr/5bin/make SHELL=/bin/sh -f - <make.tmp
	(ed) mtxinu> /bin/sh ../xx
		echo *
	make.tmp typescript
		echo *
	make.tmp typescript
	(ed) mtxinu>

I guess it's fixed here!

-- 
Ed Gould		    mt Xinu, 739 Allston Way, Berkeley, CA  94710  USA
{ucbvax,decvax}!mtxinu!ed   +1 415 644 0146

guy@rlgvax.UUCP (Guy Harris) (02/15/85)

> > I recently found the following bug (feature?) in System 3, 5, OSx Make
> > in the following shell script:

...

> I guess it's fixed here!

That's probably because you're on a 4.2BSD system; it doesn't occur
here either.  From an article explaining the bug:

> David Tilbrook, Imperial Software Technology, London England in <305@ist.UUCP>
> points up a bug in make whereby the shell's filename  expansion is suppressed
> when make is invoked:

> 	make -f - < descfile

> rather than:

> 	make -f descfile

> The bug is actually in /bin/sh.  In sh/expand.c around line 112 the shell
> attemps to open a directory to scan for file name expansions:

> 	if ((dirf = open(*s ? s : ".", 0)) > 0)

	...

> The asuumption is that open will never return 0; the check should be >= 0.

In a 4.2BSD version of the shell (any shell), this would be done with
"opendir"; in the process of changing the code to use the directory
library, one would almost certainly fix the bug (since the test would be
against a null pointer return).

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy