[PATCH] debugfs: fix encoding handling in dx_hash command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Eric Biggers <ebiggers@xxxxxxxxxx>

Fix the following bugs:

1. 'encoding' and 'hash_flags' are not initialized, causing a segfault.

2. 'hash_flags' incorrectly uses a __bitwise type.

3. The optstring doesn't contain "c" or "e", so the -c and -e options
   aren't recognized.

4. The code that handles the -e option always returns.

Fixes: ef733f1a97ec ("debugfs: support encoding when printing the file hash")
Cc: Gabriel Krisman Bertazi <krisman@xxxxxxxxxxxxxxx>
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
 debugfs/htree.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/debugfs/htree.c b/debugfs/htree.c
index 1cdb3c6a..82406d4f 100644
--- a/debugfs/htree.c
+++ b/debugfs/htree.c
@@ -310,17 +310,18 @@ errout:
 void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
 		void *infop EXT2FS_ATTR((unused)))
 {
-	ext2_dirhash_t hash, minor_hash, hash_flags;
+	ext2_dirhash_t hash, minor_hash;
 	errcode_t	err;
 	int		c;
 	int		hash_version = 0;
 	__u32		hash_seed[4];
-	const struct nls_table *encoding;
+	int		hash_flags = 0;
+	const struct nls_table *encoding = NULL;
 
 	hash_seed[0] = hash_seed[1] = hash_seed[2] = hash_seed[3] = 0;
 
 	reset_getopt();
-	while ((c = getopt (argc, argv, "h:s:")) != EOF) {
+	while ((c = getopt(argc, argv, "h:s:ce:")) != EOF) {
 		switch (c) {
 		case 'h':
 			hash_version = e2p_string2hash(optarg);
@@ -335,14 +336,16 @@ void do_dx_hash(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
 			}
 			break;
 		case 'c':
-			hash_flags = EXT4_CASEFOLD_FL;
+			hash_flags |= EXT4_CASEFOLD_FL;
 			break;
 		case 'e':
 			encoding = nls_load_table(e2p_str2encoding(optarg));
-			if (!encoding)
+			if (!encoding) {
 				fprintf(stderr, "Invalid encoding: %s\n",
 					optarg);
 				return;
+			}
+			break;
 		default:
 			goto print_usage;
 		}
-- 
2.21.0.593.g511ec345e18-goog




[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux