Re: [perl #60904] Race condition with perl -i.bk
Chip Salzenberg [Mon, 1 Dec 2008 15:01:12 +0000 (07:01 -0800)]
Message-ID: <20081201230112.GH31089@tytlal.topaz.cx>

Use mode 0600 (minus umask) for creation of the new file with -i

p4raw-id: //depot/perl@35082

doio.c

diff --git a/doio.c b/doio.c
index 5b41a78..221c5ea 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -811,8 +811,7 @@ Perl_nextargv(pTHX_ register GV *gv)
                    do_close(gv,FALSE);
                    (void)PerlLIO_unlink(SvPVX_const(sv));
                    (void)PerlLIO_rename(PL_oldname,SvPVX_const(sv));
-                   do_open(gv,(char*)SvPVX_const(sv),SvCUR(sv),PL_inplace!=0,
-                           O_RDONLY,0,NULL);
+                   do_open(gv,(char*)SvPVX_const(sv),SvCUR(sv),TRUE,O_RDONLY,0,NULL);
 #endif /* DOSISH */
 #else
                    (void)UNLINK(SvPVX_const(sv));
@@ -844,17 +843,15 @@ Perl_nextargv(pTHX_ register GV *gv)
 #endif
                }
 
-               sv_setpvn(sv,">",!PL_inplace);
-               sv_catpvn(sv,PL_oldname,oldlen);
+               sv_setpvn(sv,PL_oldname,oldlen);
                SETERRNO(0,0);          /* in case sprintf set errno */
+               if (!do_open(PL_argvoutgv,(char*)SvPVX_const(sv),SvCUR(sv),TRUE,
 #ifdef VMS
-               if (!do_open(PL_argvoutgv,(char*)SvPVX_const(sv),SvCUR(sv),
-                            PL_inplace!=0,O_WRONLY|O_CREAT|O_TRUNC,0,NULL))
+                            O_WRONLY|O_CREAT|O_TRUNC,0,
 #else
-                   if (!do_open(PL_argvoutgv,(char*)SvPVX_const(sv),SvCUR(sv),
-                            PL_inplace!=0,O_WRONLY|O_CREAT|OPEN_EXCL,0666,
-                            NULL))
+                            O_WRONLY|O_CREAT|OPEN_EXCL,0600,
 #endif
+                            NULL))
                {
                    if (ckWARN_d(WARN_INPLACE)) 
                        Perl_warner(aTHX_ packWARN(WARN_INPLACE), "Can't do inplace edit on %s: %s",