From: Eric Biggers <ebiggers@kernel.org>
To: linux-ext4@vger.kernel.org
Cc: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Subject: [PATCH] debugfs: fix encoding handling in dx_hash command
Date: Mon, 22 Apr 2019 14:01:23 -0700 [thread overview]
Message-ID: <20190422210124.181075-1-ebiggers@kernel.org> (raw)
From: Eric Biggers <ebiggers@google.com>
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@collabora.co.uk>
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
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
next reply other threads:[~2019-04-22 21:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 21:01 Eric Biggers [this message]
2019-04-23 4:07 ` [PATCH] debugfs: fix encoding handling in dx_hash command Gabriel Krisman Bertazi
2019-04-29 0:20 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190422210124.181075-1-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=krisman@collabora.co.uk \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.