[Toybox] [PATCH] cpio: Use chown pathname version
Vincent Donnefort
vdonnefort at google.com
Wed Mar 8 09:05:12 PST 2023
CPIOs archives might contain dev nodes which could also point to
unavailable drivers. In that case, fopen would simply fail, making it
impossible for cpio to change the ownership.
Switch to the pathname version for chown and stat to circumvent this
limitation.
Change-Id: I5f7202bf19f4c3d4f750cdd72ed0c467f9166da6
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 282a39b1..b1a20203 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -226,14 +226,11 @@ void cpio_main(void)
if (!S_ISREG(mode) && !S_ISLNK(mode) && !geteuid()
&& !FLAG(no_preserve_owner))
{
- int fd = open(name, O_RDONLY|O_NOFOLLOW);
struct stat st;
- if (fd != -1 && !fstat(fd, &st) && (st.st_mode&S_IFMT) == (mode&S_IFMT))
- err = fchown(fd, uid, gid);
+ if (!stat(name, &st) && (st.st_mode&S_IFMT) == (mode&S_IFMT))
+ err = chown(name, uid, gid);
else err = 1;
-
- close(fd);
}
// set timestamp
--
2.40.0.rc0.216.gc4246ad0f0-goog
More information about the Toybox
mailing list