phil@unicorn.cc.wwu.edu (Phil Nelson) (11/28/90)
Recently, I was working with a program that used the rename system call to make backup files. It used calls like rename("file","file~"). This call failed every time. After tracking down what was happening, I discovered that fs (the code for rename) checks to make sure that the old file name (file) is not a prefix of the new file name (file~). If it is a prefix, then the rename is denied. This means many rename calls will fail when it is safe to do the rename. I don't have the POSIX definition, but I presume that is not a POSIX requirement. After looking at the fs code, I decided that the "correct" test was to see if the old file name is a DIRECTORY prefix in the new name. If it is, then the rename is trying to move a directory into a subdirectory of itself. This is something that should not work. I changed the code to test for the directory prefix problem. The uuencoded, compressed cdiff follows. --Phil Nelson (phil@cs.wwu.edu, Western Washington University, Bellingham, WA) --------- table !"#$%&'()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ begin 644 link.cdiff.Z M'YV-*@*"8)/&S1H78UR\D9/F3 (J=<J </+&#@@9-T#$J*&#!@T=-3+&R)$#z MAH(6* <6/#CF8<2)%2^*Y$C#AHX9(DF:#,BSIT\5"GA>C(&#A0P9-4#T5 "y M!-.F(%ZH )'$#(@T=*[. ?%F#0L08]"4&;,&A)F%(,* L!.&81DZ>;A:A?-Fx MSIPT8MA(+"-'SL(Y+I2^>-HTC544<D#TZ 'BR9(4(/8H" $B@5005,1R94,&w M!)PP=-" :%-G3E8W;[**D:@6CIPR9M+@D0LBM$0W9>YPQ1U8Q6#*"0R#0&%:v MCILQ;>"@>,/YBYLP;<I\+<WWR^?07XOK=;.\^?/H*2 O!@$#<F+&19(XL1*$u MR8ZG3RU/S2R1>>?KHDF;!H%:M<3 :+G0VV!-!7=8<<@I9Y]ST$D'@@@NB)#"t M8C" P <?(""87'=D,!C=5Q!&.&$/Y8%P'@CIK=?>>RBU,%111]D 0HLMP =5s M5%-5=556:6S5U5=AC57668FIQ99;<-%&EUUXZ04"7W[) 9A@A%UUV'F,.0:9r M9,!=1M]F]X&67VFGI0;":FF!0$8:KXU!QT)QN0:;;+39QE]NNY4QX&25"8<"q M<708ER"''CI(G1S6B9E=H-L1^ET9X2G&6'E\)G"C"28,=VBBH6VA71G<+?AHp M"EU("L()+YP0Z8DILN>>C95YJ9E]GHDY&IG\F8DF@(D)2&6!?FJHH'<-@B@Bo 4A19B**RCQ3XHH(04FJ<8BNJY^AY]n m end
cechew@bruce.cs.monash.OZ.AU (Earl Chew) (11/28/90)
In <1990Nov28.001925.24250@unicorn.cc.wwu.edu> phil@unicorn.cc.wwu.edu (Phil Nelson) writes: >Recently, I was working with a program that used the rename system call >to make backup files. It used calls like rename("file","file~"). This >call failed every time. After tracking down what was happening, I >discovered that fs (the code for rename) checks to make sure that the >old file name (file) is not a prefix of the new file name (file~). If Actually, there is a problem with both the original and the proposed patch. Assume that the cwd is /a and that there is a directory named /a/b. Consider: rename("b","b~"); /* failed original */ rename("b","/a/b/c"); /* fails proposed patch */ It may get worse once symbolic links are introduced. Enclosed is a copy of a patch that Bruce sent me that appears to cure the problem. Earl ------------------------------------------------------------------------------- table !"#$%&'()*+,-./0123456789:;<=>? @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ begin 644 link.c.cdif.Z M'YV0*@*"8)/&S1H78UR\D9/F3 (J:.J F%(&#@@0-D# R*&CA@T=,6J B)$Cz M!PP%+5(.+'APS,.($RM>S+BQX\>0(TN>#,BSIT\5"GB"D!$#!PL9,D3V5'"1y MZ440+U2 2&(&1!HZ5N> >+.&!8@Q:,J,60/"S$(084#8"<.P#)T\6ZO">3-Gx M3AHQ;,J *"-'SL(Y+D"H>.'T8IJJ*.2 Z-$#Q),E*4#L41 "1(*H("#J?<.&w M# @X8>B@ =&FSARL;MY@%:,W+1PY9<RDP1,7A&B];LK<V9H[\&#*E@^#0'%:v MCILQ;>"@X$SFBYLP;<IX-<WW"VC17HOG=;.\LW/H95)$9JPQLN+&19(XL1*$u MR0ZG3B]+U;RU\^?0HTN?!I%ZM=[ 9[G@&V$7)2 <<73(@9QRS'T7G5<BN"!"t M"HS! (??(!0W(+=-??<@R!$*"&%/<!@WF(@I+=>>^^EU,)011U%PPT@N-@"s M?$]!)1555F&5AE9<>0666&29I5A::[7U5FUSU7577GOU]=> A5F%V'F-/1;9r M9)7)EUE8]7E6T!MDZ*4?:JJ!P!I:&M8!!U]DI ';&'0L!-<;5=W&GVX#A;%?q MG')0V>6!PS68!APM^)#&%VV0J9<)4WU!1190%#%>8TE\04024A0Q!!5/2)'%p MEL ED$!Q==!I56IE"I;;'5_,X2:<<L+Q7I>G)IBJCZSJI4)N>-#AG&ZQSBH'o MH+8"5VH"9+CYQ9AEHO!JL6\>6RN*TR*;PJV6)7 '&FE B0(54E1AJ63+&HC8n MM+)6B^QBC1D*!ZFXFGI>BNJQYUZZ"8@!6QAK<&MJ GVD"ZRP[!K[;F-AD+'6m M<65(2VR[M,H!!X0"3BBPJ7#4(2RT$2?L;JW;IGO@P</"2K&U%L.[I\H*D\ROl MOV4 O(.78H0Q%EI8^94FH&+5*0=<O]4K<L46-8;RT2PG6^_)$\?<,GE.),'$k M%^H]0<2Y7'9K*F9-_&B7&V>$F/%>;B281V @!%%7'='9!N8=?]$AJ-<)W*NBj MOAN;2K/-Z1:,:Q^6+=OQQ[U*#//(%I?<91\)X&@99O0Q=Y]HI)F&IG\@ *B8i C@((1&!QB&R;7H8/2F3UAA1=F6#J#WGV8NHBKEW@B>OFRJ !Hh g end ------------------------------------------------------------------------------- -- Earl Chew, Dept of Computer Science, Monash University, Australia 3168 EMAIL: cechew@bruce.cs.monash.edu.au PHONE: 03 5655447 FAX: 03 5655146 ----------------------------------------------------------------------