summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2016-01-26 19:37:14 +0100
committerNiels Möller <nisse@lysator.liu.se>2016-01-26 19:37:14 +0100
commit99f954f7ff49be41825aeeb852f9eec8c1de3707 (patch)
tree01d07b50d0be51e0b76961d6cc709ac5c93e3992
parent3566620826881a74ea0d2d3464a82f7129c02188 (diff)
downloadnettle-99f954f7ff49be41825aeeb852f9eec8c1de3707.tar.gz
Fix handling of unrecognized options for nettle-hash and nettle-pbkdf2.
-rw-r--r--ChangeLog8
-rw-r--r--tools/nettle-hash.c25
-rw-r--r--tools/nettle-pbkdf2.c5
3 files changed, 29 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index ff8d7f40..e474c8d6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-01-26 Niels Möller <nisse@lysator.liu.se>
+
+ * tools/nettle-pbkdf2.c (main): Fix handling of unrecognized
+ options. Bug reported by Dongsheng Zhang. Display usage message
+ and exit non-zero. Also added "Usage: "-prefix to the message.
+ * tools/nettle-hash.c (usage): New function, extracted from main.
+ (main): Analogous fix for unrecognized options.
+
2016-01-23 Niels Möller <nisse@lysator.liu.se>
* nettle.texinfo: Set UPDATED-FOR to 3.2.
diff --git a/tools/nettle-hash.c b/tools/nettle-hash.c
index c78656ad..b669a6ee 100644
--- a/tools/nettle-hash.c
+++ b/tools/nettle-hash.c
@@ -134,6 +134,19 @@ digest_file(const struct nettle_hash *alg,
return 1;
}
+static void
+usage (FILE *f)
+{
+ fprintf(f, "Usage: nettle-hash -a ALGORITHM [OPTIONS] [FILE ...]\n"
+ "Options:\n"
+ " --help Show this help.\n"
+ " -V, --version Show version information.\n"
+ " --list List supported hash algorithms.\n"
+ " -a, --algorithm=ALG Hash algorithm to use.\n"
+ " -l, --length=LENGTH Desired digest length (octets)\n"
+ " --raw Raw binary output.\n");
+}
+
/* FIXME: Be more compatible with md5sum and sha1sum. Options -c
(check), -b (binary), -t (text), and output format with hex hash
sum, optional star (meaning binary mode), and file name. */
@@ -165,15 +178,11 @@ main (int argc, char **argv)
{
default:
abort();
+ case '?':
+ usage (stderr);
+ return EXIT_FAILURE;
case OPT_HELP:
- printf("nettle-hash -a ALGORITHM [OPTIONS] [FILE ...]\n"
- "Options:\n"
- " --help Show this help.\n"
- " -V, --version Show version information.\n"
- " --list List supported hash algorithms.\n"
- " -a, --algorithm=ALG Hash algorithm to use.\n"
- " -l, --length=LENGTH Desired digest length (octets)\n"
- " --raw Raw binary output.\n");
+ usage (stdout);
return EXIT_SUCCESS;
case 'V':
printf("nettle-hash (" PACKAGE_STRING ")\n");
diff --git a/tools/nettle-pbkdf2.c b/tools/nettle-pbkdf2.c
index b4e74a26..16040c38 100644
--- a/tools/nettle-pbkdf2.c
+++ b/tools/nettle-pbkdf2.c
@@ -51,7 +51,7 @@
static void
usage (FILE *f)
{
- fprintf(f, "nettle-pbkdf2 [OPTIONS] SALT\n"
+ fprintf(f, "Usage: nettle-pbkdf2 [OPTIONS] SALT\n"
"Options:\n"
" --help Show this help.\n"
" -V, --version Show version information.\n"
@@ -97,6 +97,9 @@ main (int argc, char **argv)
{
default:
abort();
+ case '?':
+ usage (stderr);
+ return EXIT_FAILURE;
case OPT_HELP:
usage (stdout);
return EXIT_SUCCESS;