57 lines
1.4 KiB
Diff
57 lines
1.4 KiB
Diff
From 9cfd62d24ea564c69f09b9f129b39d4460504cec Mon Sep 17 00:00:00 2001
|
|
From: Lee Duncan <lduncan@suse.com>
|
|
Date: Tue, 12 May 2020 16:01:50 +0800
|
|
Subject: [PATCH] Fix issue where 'iscsi-iname -p' core dumps
|
|
|
|
Fix issue where 'iscsi-iname -p' core dumps
|
|
|
|
Signed-off-by: Lee Duncan <lduncan@suse.com>
|
|
---
|
|
utils/iscsi-iname.c | 19 +++++++++++++++----
|
|
1 file changed, 15 insertions(+), 4 deletions(-)
|
|
|
|
diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c
|
|
index ad843a0..173e632 100644
|
|
--- a/utils/iscsi-iname.c
|
|
+++ b/utils/iscsi-iname.c
|
|
@@ -40,6 +40,14 @@
|
|
* 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,14 +76,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: Prexfix 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 {
|
|
--
|
|
1.8.3.1
|
|
|