From: Tyler H. <ty...@ca...> - 2017-11-29 17:07:06
|
This patch fixes a bug that caused symlinks created by unsquashfs to use the current time for atime and mtime rather than the times present in the squashfs archive. The timestamps are set using utimensat(2) which does not dereference the symlink when the AT_SYMLINK_NOFOLLOW flag is used. The utimensat(2) system call supports nanosecond precision but that's not needed by squashfs so timespec.tv_nsec is unconditionally set to 0. Signed-off-by: Tyler Hicks <ty...@ca...> --- squashfs-tools/unsquashfs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c index c5e0876..5141c27 100644 --- a/squashfs-tools/unsquashfs.c +++ b/squashfs-tools/unsquashfs.c @@ -1089,7 +1089,12 @@ int create_inode(char *pathname, struct inode *i) file_count ++; break; case SQUASHFS_SYMLINK_TYPE: - case SQUASHFS_LSYMLINK_TYPE: + case SQUASHFS_LSYMLINK_TYPE: { + struct timespec times[2] = { + { i->time, 0 }, + { i->time, 0 } + }; + TRACE("create_inode: symlink, symlink_size %lld\n", i->data); @@ -1103,6 +1108,13 @@ int create_inode(char *pathname, struct inode *i) break; } + if (utimensat(AT_FDCWD, pathname, times, + AT_SYMLINK_NOFOLLOW) == -1) { + ERROR("create_inode: failed to set time on " + "%s, because %s\n", pathname, + strerror(errno)); + } + write_xattr(pathname, i->xattr); if(root_process) { @@ -1115,6 +1127,7 @@ int create_inode(char *pathname, struct inode *i) sym_count ++; break; + } case SQUASHFS_BLKDEV_TYPE: case SQUASHFS_CHRDEV_TYPE: case SQUASHFS_LBLKDEV_TYPE: -- 2.7.4 |