Dear cpio maintainers:
I found out that I didn't attach the patch correctly so I re-upload it. I want to follow up on the email regarding error function when failing to create symlink. Thanks in advance for any feedback or suggestions. Before applying this patch: ln -s /tmp soft_link echo soft_link | cpio -oF test_cpio_soft.cpio cp test_cpio_soft.cpio /boot/efi cd /boot/efi cpio -ivF test_cpio_soft.cpio cpio: soft_link: Cannot create symlink to ‘/tmp’: Operation not permitted # vfat filesystem don't support symlink soft_link 1 block [root@localhost efi]# echo $? 2 After: [root@localhost efi]# cpio -ivF test_cpio_soft.cpio cpio: /tmp: Cannot symlink to ‘soft_link’: Operation not permitted soft_link 1 block [root@localhost efi]# echo $? 0 Reasons for proposing this patch: 1. Exit code 2 means 'Out-of-phase error. A file header is corrupt or in the wrong format', and I don't think 'operation not permitted' falls into this description. So setting exit code to 0 may be a better option. 2. As I mentioned before, exit code not equal to 0 usually means failure and cpio should terminate, but cpio don't terminate. So I think it's better to keep exit code as 0. Best Ziyang At 2023-07-04 20:53:46, "youngchen" <[email protected]> wrote: Dear cpio maintainers: I would like to propose a patch because after fix of CVE-2015-1197, cpio-2.14 set exit code to 2 when failing to create a symlink. In fact, in function copyin_link, cpio use symlink_error() instead of error() function. From the user's perspective, exit code not equal to 0 means error and cpio should terminate, but cpio don't terminate. So I think it's better to keep exit code as 0 when failing to create a symlink, which is consistent with cpio-2.13. I am very happy to hear any feedback or suggestions regarding this patch. Best Ziyang At 2023-06-23 11:16:38, "youngchen" <[email protected]> wrote: Hi cpio miantainers, I found that cpio has changed exit code from 0 to 2 when failed to create a symbolic link in this fix: http://git.savannah.gnu.org/cgit/cpio.git/commit/?id=376d663340a9dc91c91a5849e5713f07571c1628 and I am writing to ask is this an expected behavior? Before this commit, in copyin_link() function, when failing to create a symbolic link, cpio used error() to record failure. After this commit, cpio uses symlink_error () to record failure. However, symlink_error() will set the exit code to 2 which means failure. May I know the reason for changing error function to symlink_error function? Below are the steps to reproduce the problem: ``` dd if=/dev/zero of=/root/tempfsvfat bs=1M count=4000 mkfs.vfat /root/tempfsvfat mkdir vfat-file mount tempfsvfat vfat-file/ # create a vfat file system which don't support symlink cd vfat-file/ cp -ar /boot/initramfs-4.19.90-2109.1.0.0108.oe1.x86_64.img . zcat *.img | cpio -di echo $? ``` We may replace '/boot/initramfs-4.19.90-2109.1.0.0108.oe1.x86_64.img' file with any other initramfs file under /boot/ directory in Linux system. The cpio will always fail to extract symbolic link under vfat-file directory which is normal behavior because vfat filesystem doesn't support symbolic link, but the return value of 'echo $?' has changed from 0 to 2 when using the latest cpio version. In my opinion, cpio should terminate once it sets the exit code to 2 which means failure, but cpio didn't do that. So what is the expected exit code when failing to create a symbolic link? Best Ziyang
0001-Do-not-set-exit-code-to-2-when-failing-to-create-sym.patch
Description: Binary data
