From: Chip Salzenberg Date: Mon, 1 Dec 2008 15:01:12 +0000 (-0800) Subject: Re: [perl #60904] Race condition with perl -i.bk X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=30fc4309ed1e3ccf7d2e8d9d3401a485e1991375;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #60904] Race condition with perl -i.bk 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 --- diff --git a/doio.c b/doio.c index 5b41a78..221c5ea 100644 --- 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",