[comp.sources.bugs] A bug in perl3

greim@sbsvax.UUCP (Michael Greim) (09/12/89)

This is a bug report and quick fix to help people fix perl until
Larry Wall issues an official patch. I have sent this also to Larry
Wall.

	-mg


Bug in perl3.

Priority: medium

Symptoms:
	The test op.mkdir fails.
	If perl tries to "mkdir" a directory which already exists, it thinks
	the operation did succeed, although it failed.

Diagnosis:
	The machine has no library function (system call) mkdir. So perl
	tries to emulate the call by forking off the program /bin/mkdir.
	It then reads the output from this command and decides whether
	it succeeded or not by :
	- if there is no text, it succeeded
	- if there is text, examine it. What error message was it? Set
		errno accordingly.

	On the machine on which I found this bug, mkdir returns status 1 and
	a text which is not a valid error message. Thus the error message
	was not found, and the return-value for mkdir was not set.
	Below is the relevant code from eval.c
	Add the line marked by "mg".
	(Sorry: no context diffs, I have changed the lines by adding test output)

-------- cut here ---------
    case O_MKDIR:
	tmps = str_get(st[1]);
	anum = (int)str_gnum(st[2]);
#ifdef TAINT
	taintproper("Insecure dependency in mkdir");
#endif
#ifdef MKDIR
	value = (double)(mkdir(tmps,anum) >= 0);
#else
	(void)sprintf(buf,"mkdir %s 2>&1",tmps);
      one_liner:
	rsfp = mypopen(buf,"r");
	if (rsfp) {
	    *buf = '\0';
	    tmps2 = fgets(buf,sizeof buf,rsfp);
	    (void)mypclose(rsfp);
	    if (tmps2 != Nullch) {
		for (errno = 1; errno <= sys_nerr; errno++) {
		    if (instr(buf,sys_errlist[errno]))	/* you don't see this */
			goto say_zero;
		}
		errno = 0;
		goto say_zero;		/* mg, 11-sep-89 Note: errno is not set correctly */
	    }
	    else
		value = 1.0;
	}
	else
	    goto say_zero;
#endif
	goto donumset;
    case O_RMDIR:
-------- cut here ---------

	The value of errno is not set correctly. What should the
	correct value be ???


Absorb, apply and enjoy,
		-mg
-- 
Michael Greim    Email : greim@sbsvax.informatik.uni-saarland.dbp.de
                 or    : ...!uunet!unido!sbsvax!greim
[.signature removed by the board of censors for electronic mail's main
executive computer because it contained a four letter word ("word")]