Module Name:    src
Committed By:   lukem
Date:           Sat Jun 10 12:46:32 UTC 2023

Modified Files:
        src/external/bsd/libarchive/dist/libarchive: archive_read_disk_posix.c

Log Message:
libarchive: fail if name_max is 0

Add error handling to the USE_READDIR_R code paths that set name_max
from struct statfs or statvfs; if the determined name_max == 0
then return an error.

Avoids a crash in tree_dir_next_posix() when the calculation of
dirent_size from name_max is too small for the memory allocated
for struct dirent.

Submitted to upstream in pull request
        https://github.com/libarchive/libarchive/pull/1903

Should fix PR bin/56080


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c
diff -u src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.2 src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.3
--- src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c:1.2	Mon Mar 29 15:31:46 2021
+++ src/external/bsd/libarchive/dist/libarchive/archive_read_disk_posix.c	Sat Jun 10 12:46:32 2023
@@ -1653,6 +1653,11 @@ setup_current_filesystem(struct archive_
 	else
 		t->current_filesystem->name_max = nm;
 #endif
+	if (t->current_filesystem->name_max == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Cannot determine name_max");
+		return (ARCHIVE_FAILED);
+	}
 #endif /* USE_READDIR_R */
 	return (ARCHIVE_OK);
 }
@@ -1726,6 +1731,11 @@ setup_current_filesystem(struct archive_
 
 	/* Set maximum filename length. */
 	t->current_filesystem->name_max = sfs.f_namemax;
+	if (t->current_filesystem->name_max == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Cannot determine name_max");
+		return (ARCHIVE_FAILED);
+	}
 	return (ARCHIVE_OK);
 }
 
@@ -1858,6 +1868,11 @@ setup_current_filesystem(struct archive_
 #if defined(USE_READDIR_R)
 	/* Set maximum filename length. */
 	t->current_filesystem->name_max = sfs.f_namelen;
+	if (t->current_filesystem->name_max == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Cannot determine name_max");
+		return (ARCHIVE_FAILED);
+	}
 #endif
 	return (ARCHIVE_OK);
 }
@@ -1939,6 +1954,11 @@ setup_current_filesystem(struct archive_
 #if defined(USE_READDIR_R)
 	/* Set maximum filename length. */
 	t->current_filesystem->name_max = sfs.f_namemax;
+	if (t->current_filesystem->name_max == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Cannot determine name_max");
+		return (ARCHIVE_FAILED);
+	}
 #endif
 	return (ARCHIVE_OK);
 }
@@ -1993,6 +2013,11 @@ setup_current_filesystem(struct archive_
 	else
 		t->current_filesystem->name_max = nm;
 #  endif /* _PC_NAME_MAX */
+	if (t->current_filesystem->name_max == 0) {
+		archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
+		    "Cannot determine name_max");
+		return (ARCHIVE_FAILED);
+	}
 #endif /* USE_READDIR_R */
 	return (ARCHIVE_OK);
 }

Reply via email to