develooper Front page | perl.perl5.porters | Postings from February 2004

Re: [perl #24521] make test breaks permissions on /dev/tty

Thread Previous
Dave Mitchell
February 29, 2004 10:43
Re: [perl #24521] make test breaks permissions on /dev/tty
Message ID:
On Wed, Nov 19, 2003 at 12:39:27AM -0000, (via RT) wrote:
> When running "make test" from the perl source tree, the permissions
> of /dev/tty get changed from 0666 to 2775.  This obviously breaks
> a unix system pretty badly.

Thanks for the report, I'm sorry it it's taken us so long to respond.

I've been able to reduce the problem to the following:

    $ mkdir foo; chmod 2777 foo; # needs SUID or SGID bit set
    $ touch bar;
    $ perl -i -e '$x=<>;$x=<>' foo < bar
    Can't do inplace edit: foo is not a regular file at -e line 1.

    (bar now has permissions 2777)

This is because on the second read, Perl attempts to restore the
permissions on the previous file, but because the open of the previous
file failed (it wont let you do an inplace edit of a directory),
the variable containing the previous file descriptor is still set at 0,
so it ends up doing an fchmod(0,...). Whoops!

This is now fixed in the development version of Perl by the following


Any [programming] language that doesn't occasionally surprise the
novice will pay for it by continually surprising the expert.
   -- Larry Wall

Change 22415 by davem@davem-percy on 2004/02/29 18:06:45

	 [perl #24521] make test breaks permissions on /dev/tty
	 perl -i could fchmod(stdin) by mistake

Affected files ...

... //depot/perl/doio.c#236 edit

Differences ...

==== //depot/perl/doio.c#236 (text) ====

@@ -723,11 +723,13 @@
     if (PL_filemode & (S_ISUID|S_ISGID)) {
 	PerlIO_flush(IoIFP(GvIOn(PL_argvoutgv)));  /* chmod must follow last write */
 #ifdef HAS_FCHMOD
-	(void)fchmod(PL_lastfd,PL_filemode);
+	if (PL_lastfd != -1)
+	    (void)fchmod(PL_lastfd,PL_filemode);
+    PL_lastfd = -1;
     PL_filemode = 0;
     if (!GvAV(gv))
         return Nullfp;

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About