]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: fix encoding handling in dx_hash command
authorEric Biggers <ebiggers@google.com>
Mon, 29 Apr 2019 00:35:21 +0000 (20:35 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 29 Apr 2019 00:35:25 +0000 (20:35 -0400)
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")
Reviewed-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/htree.c

index 1cdb3c6a5bb7c1620fd8fb6bab26e5f4919c983a..82406d4fe317ec68102a687d1c98b558f41ffcaf 100644 (file)
@@ -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;
                }