<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 3, 2021 at 1:56 AM enh <<a href="mailto:enh@google.com" target="_blank" class="cremed">enh@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 1, 2021 at 5:43 PM Rob Landley <<a href="mailto:rob@landley.net" target="_blank" class="cremed">rob@landley.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2/28/21 12:29 PM, Yi-yo Chiang wrote:<br>
> (I'll try to keep it short)<br>
> <br>
> My original motivation to send this patch is that my coworker found out (when he<br>
> was working with initramfs) that "cpio -u" behaves differently on toybox<br>
> compared to the GNU's implementation.<br>
<br>
"What was the actual problem?" "My coworker noticed this existed."<br>
<br>
That's... not a use case?<br></blockquote><div><br></div><div>from the bugs, i think the original bug was the "File exists" -d bug from the ramdisk cpio file, and they hit the -u behavior difference trying to work around that before realizing that -d was the real problem? (or maybe -u was an attempt to produce a small repro case for the -d bug. Or both!)</div><div><br></div><div>i'll sync AOSP today anyway. thanks!</div></div></div></blockquote><div><br></div><div>It's the opposite, we have problems with "-u", and I hit the "-d" thing when I'm trying to produce minimal repro steps.</div><div><div>I recall the original use case is that we were trying to unpack an initramfs file, where the initramfs consists of multiple cpio archives concatenated.</div><div>So even if the extraction destination is empty, name conflict still happens, because name conflict is happening between two component cpio archives.</div><div>e.g. initramfs consists of two cpio archives, and both archives are creating the same directory. </div></div><div><br></div><div>Thanks, it's (f1be076b52ad) working now!</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
     } else if (S_ISLNK(mode)) {<br>
       data = strpad(afd, size, 0);<br>
-      if (!test) err = symlink(data, name);<br>
+      if (!test) {<br>
+        err = symlink(data, name);<br>
+        // Can't get a filehandle to a symlink, so do special chown<br>
+        if (!err && !geteuid() && !FLAG(no_preserve_owner))<br>
+          err = lchown(name, uid, gid);<br>
+      }<br>
       free(data);<br>
-      // Can't get a filehandle to a symlink, so do special chown<br>
-      if (!err && !geteuid() && !FLAG(no_preserve_owner))<br>
-        err = lchown(name, uid, gid);<br>
<br></blockquote></div></div></blockquote></div><div><br></div><div><div>Following are more testcases...</div><div><br></div><div><font face="monospace">$ ln -s target_name a</font></div><div><font face="monospace">$ stat -c '%u' a</font></div><font face="monospace">584303<br></font><div><font face="monospace">$ sudo chown --no-dereference 0 a</font></div><div><font face="monospace">$ stat -c '%u' a</font></div><font face="monospace">0</font></div><div><font face="monospace">$ # Verify that the owner of 'a' is changed to root</font></div><div><div><font face="monospace">$ echo a | cpio -o -H newc >a.cpio</font></div><div><font face="monospace">$ rm a</font></div><div><font face="monospace">$ touch a</font></div><div><font face="monospace">$ stat -c '%u' a</font></div><font face="monospace">584303</font></div><div><font face="monospace">$ # Verify that the owner of 'a' is not root</font></div><div><font face="monospace">$ sudo ./toybox cpio -i -t <a.cpio<br>a</font><div></div></div><div><font face="monospace">$ stat -c '%u' a</font></div><font face="monospace">0</font><div><font face="monospace"><br></font>The owner of 'a' is modified, albeit the "-t" (test) flag. I expect "-t" to only show the list of files to stdout, and not modify/create any file?</div><div><br><div><div>-- <br><div dir="ltr"><div dir="ltr"><table width="90%" border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:0px;font-family:"Times New Roman";max-width:348px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="padding:0px"><table border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:20px 0px 0px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td valign="top" style="padding:0px 20px 0px 0px;vertical-align:top;border-right:1px solid rgb(213,213,213)"><img src="https://i.imgur.com/eGpkLls.png" width="200" height="64"><br></td><td style="padding:0px 0px 0px 20px"><table border="0" cellspacing="0" cellpadding="0" style="margin:0px;padding:0px"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:1px 0px 5px;font-size:13px;line-height:13px;color:rgb(56,58,53);font-weight:700">Yi-yo Chiang</td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 5px;font-size:11px;line-height:13px;color:rgb(56,58,53)">Software Engineer</td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 5px;font-size:11px;line-height:13px;color:rgb(56,58,53)"><a href="mailto:yochiang@google.com" target="_blank" class="cremed">yochiang@google.com</a></td></tr><tr style="margin:0px;padding:0px"><td colspan="2" style="font-family:Arial,Helvetica,Verdana,sans-serif;padding:0px 0px 3px;font-size:11px;line-height:13px;color:rgb(3,112,248)"></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></div></div></div></div></div>