lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230121203230.27624-29-ebiggers@kernel.org>
Date:   Sat, 21 Jan 2023 12:32:20 -0800
From:   Eric Biggers <ebiggers@...nel.org>
To:     linux-ext4@...r.kernel.org
Subject: [PATCH 28/38] misc/create_inode: simplify logic in scandir()

From: Eric Biggers <ebiggers@...gle.com>

The control flow in scandir() (only used on Windows) confuses gcc into
thinking that *name_list is not always set on success, which causes a
-Wmaybe-uninitialized warning in __populate_fs().  As far as I can tell
it's a false positive; however, avoid it by cleanly separating the
success and failure cases in scandir().

Signed-off-by: Eric Biggers <ebiggers@...gle.com>
---
 misc/create_inode.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/misc/create_inode.c b/misc/create_inode.c
index 7ce69c2b0..6e61d98e6 100644
--- a/misc/create_inode.c
+++ b/misc/create_inode.c
@@ -763,39 +763,33 @@ static int scandir(const char *dir_name, struct dirent ***name_list,
 			size_t new_list_size = temp_list_size + 32;
 			struct dirent **new_list = (struct dirent**)realloc(
 				temp_list, new_list_size * sizeof(struct dirent*));
-			if (new_list == NULL) {
-				goto out;
-			}
+			if (new_list == NULL)
+				goto out_err;
 			temp_list_size = new_list_size;
 			temp_list = new_list;
 		}
 		// add the copy of dirent to the list
 		temp_list[num_dent] = (struct dirent*)malloc((dent->d_reclen + 3) & ~3);
 		if (!temp_list[num_dent])
-			goto out;
+			goto out_err;
 		memcpy(temp_list[num_dent], dent, dent->d_reclen);
 		num_dent++;
 	}
+	closedir(dir);
 
 	if (compar != NULL) {
 		qsort(temp_list, num_dent, sizeof(struct dirent*),
 		      (int (*)(const void*, const void*))compar);
 	}
-
-        // release the temp list
 	*name_list = temp_list;
-	temp_list = NULL;
+	return num_dent;
 
-out:
-	if (temp_list != NULL) {
-		while (num_dent > 0) {
-			free(temp_list[--num_dent]);
-		}
-		free(temp_list);
-		num_dent = -1;
-	}
+out_err:
 	closedir(dir);
-	return num_dent;
+	while (num_dent > 0)
+		free(temp_list[--num_dent]);
+	free(temp_list);
+	return -1;
 }
 
 static int alphasort(const struct dirent **a, const struct dirent **b) {
-- 
2.39.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ