summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorLee Duncan <lduncan@suse.com>2020-03-25 18:00:50 -0700
committerLee Duncan <lduncan@suse.com>2020-03-25 18:00:50 -0700
commitb32f59619c32ed6cd136194d92c649b74926c6f2 (patch)
treecc97c62dfd2cd82bf3def1384712476b5d6cb0c6 /utils
parent496f5c3f40ce5893ddb3c6e5314a21fc41652696 (diff)
downloadopen-iscsi-b32f59619c32ed6cd136194d92c649b74926c6f2.tar.gz
Fix issue where "iscsi-iname -p" core dumps.
While I was at it, I made the usage message a function and made it print to stderr insted of stdout.
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile2
-rw-r--r--utils/iscsi-iname.c17
2 files changed, 14 insertions, 5 deletions
diff --git a/utils/Makefile b/utils/Makefile
index f65f1e7..aed3bb0 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -1,7 +1,7 @@
# This Makefile will work only with GNU make.
CFLAGS ?= -O2 -fno-inline -g
-CFLAGS += -Wall -Wstrict-prototypes
+CFLAGS += -Wall -Wextra -Wstrict-prototypes
PROGRAMS = iscsi-iname
all: $(PROGRAMS)
diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c
index da850dc..0f587e1 100644
--- a/utils/iscsi-iname.c
+++ b/utils/iscsi-iname.c
@@ -40,6 +40,13 @@
* a seperator and 12 characters (6 random bytes in hex representation) */
#define PREFIX_MAX_LEN 210
+static void usage(void)
+{
+ fprintf(stderr, "Usage: iscsi-iname [-h | --help | -p <prefix>]\n");
+ fprintf(stderr, "where <prefix> has max length of %d\n",
+ PREFIX_MAX_LEN);
+}
+
int
main(int argc, char *argv[])
{
@@ -68,15 +75,17 @@ main(int argc, char *argv[])
"on every invocation.\n");
exit(0);
} else if ( strcmp(prefix, "-p") == 0 ) {
+ if (argc != 3) {
+ usage();
+ exit(1);
+ }
prefix = argv[2];
if (strnlen(prefix, PREFIX_MAX_LEN + 1) > PREFIX_MAX_LEN) {
- printf("Error: Prefix cannot exceed %d "
- "characters.\n", PREFIX_MAX_LEN);
+ usage();
exit(1);
}
} else {
- printf("\nUsage: iscsi-iname [-h | --help | "
- "-p <prefix>]\n");
+ usage();
exit(0);
}
} else {