git: e81d55b43948 - main - tarfs: Support tar files which include file modes with permissions.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Thu, 16 Mar 2023 12:20:00 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=e81d55b43948e4ebcd20a9563521aae54ab727cc

commit e81d55b43948e4ebcd20a9563521aae54ab727cc
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-03-16 11:31:10 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-03-16 11:31:22 +0000

    tarfs: Support tar files which include file modes with permissions.
    
    Sponsored by:   Juniper Networks, Inc.
    Sponsored by:   Klara, Inc.
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D39020
---
 sys/fs/tarfs/tarfs_vfsops.c      | 4 ++--
 tests/sys/fs/tarfs/tarfs_test.sh | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/fs/tarfs/tarfs_vfsops.c b/sys/fs/tarfs/tarfs_vfsops.c
index 9d7297eb9d73..837fc7644ac1 100644
--- a/sys/fs/tarfs/tarfs_vfsops.c
+++ b/sys/fs/tarfs/tarfs_vfsops.c
@@ -515,12 +515,12 @@ again:
 
 	/* get standard attributes */
 	num = tarfs_str2int64(hdrp->mode, sizeof(hdrp->mode));
-	if (num < 0 || num > ALLPERMS) {
+	if (num < 0 || num > (S_IFMT|ALLPERMS)) {
 		TARFS_DPF(ALLOC, "%s: invalid file mode at %zu\n",
 		    __func__, TARFS_BLOCKSIZE * (blknum - 1));
 		mode = S_IRUSR;
 	} else {
-		mode = num;
+		mode = num & ALLPERMS;
 	}
 	num = tarfs_str2int64(hdrp->uid, sizeof(hdrp->uid));
 	if (num < 0 || num > UID_MAX) {
diff --git a/tests/sys/fs/tarfs/tarfs_test.sh b/tests/sys/fs/tarfs/tarfs_test.sh
index 50d98f857e06..d0624b79eb2d 100644
--- a/tests/sys/fs/tarfs/tarfs_test.sh
+++ b/tests/sys/fs/tarfs/tarfs_test.sh
@@ -59,6 +59,7 @@ tarfs_basic_body() {
 	atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/short_link)"
 	atf_check_equal "$(stat -f%d,%i "${mnt}"/sparse_file)" "$(stat -L -f%d,%i "${mnt}"/long_link)"
 	atf_check_equal "$(sha256 -q "${mnt}"/sparse_file)" ${sum}
+	atf_check_equal "$(stat -f%p "${mnt}"/sparse_file)" 100644
 	atf_check_equal "$(stat -f%l "${mnt}"/sparse_file)" 2
 	atf_check_equal "$(stat -f%l "${mnt}"/hard_link)" 2
 }