Skip to contentSkip to conversation

debugfs: fix encoding handling in dx_hash command

PATCH Applied Eric Biggers 3 participants 3 messages Apr 22, 2019 – Apr 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 debugfs: fix encoding handling in dx_hash command

From: Eric Biggers <[email protected]>

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 <[email protected]>
---
 debugfs/htree.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
debugfs/htree.c +8 -5
index 1cdb3c6a..82406d4f 100644
@@ -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;
 		}
Signature · 1 line
2.21.0.593.g511ec345e18-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Eric Biggers

From: Eric Biggers <[email protected]>

Fix the following bugs:

Quoted 9 lines

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.

Ugly. Thanks for finding it.

Signature · 1 line
Gabriel Krisman Bertazi
#2 lore raw
Quoted 13 lines · Gabriel Krisman Bertazi
Quoted 11 lines · Eric Biggers

From: Eric Biggers <[email protected]>

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.

Quoted 6 lines
Quoted 2 lines

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

Ugly. Thanks for finding it.

Thanks, applied.

- Ted