You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

  1. From b32f59619c32ed6cd136194d92c649b74926c6f2 Mon Sep 17 00:00:00 2001
  2. From: Lee Duncan <lduncan@suse.com>
  3. Date: Wed, 25 Mar 2020 18:00:50 -0700
  4. Subject: [PATCH] Fix issue where "iscsi-iname -p" core dumps.
  5. While I was at it, I made the usage message a function
  6. and made it print to stderr insted of stdout.
  7. ---
  8. utils/Makefile | 2 +-
  9. utils/iscsi-iname.c | 17 +++++++++++++----
  10. 2 files changed, 14 insertions(+), 5 deletions(-)
  11. diff --git a/utils/Makefile b/utils/Makefile
  12. index f65f1e79..aed3bb0a 100644
  13. --- a/utils/Makefile
  14. +++ b/utils/Makefile
  15. @@ -1,7 +1,7 @@
  16. # This Makefile will work only with GNU make.
  17. CFLAGS ?= -O2 -fno-inline -g
  18. -CFLAGS += -Wall -Wstrict-prototypes
  19. +CFLAGS += -Wall -Wextra -Wstrict-prototypes
  20. PROGRAMS = iscsi-iname
  21. all: $(PROGRAMS)
  22. diff --git a/utils/iscsi-iname.c b/utils/iscsi-iname.c
  23. index da850dca..0f587e1e 100644
  24. --- a/utils/iscsi-iname.c
  25. +++ b/utils/iscsi-iname.c
  26. @@ -40,6 +40,13 @@
  27. * a seperator and 12 characters (6 random bytes in hex representation) */
  28. #define PREFIX_MAX_LEN 210
  29. +static void usage(void)
  30. +{
  31. + fprintf(stderr, "Usage: iscsi-iname [-h | --help | -p <prefix>]\n");
  32. + fprintf(stderr, "where <prefix> has max length of %d\n",
  33. + PREFIX_MAX_LEN);
  34. +}
  35. +
  36. int
  37. main(int argc, char *argv[])
  38. {
  39. @@ -68,15 +75,17 @@ main(int argc, char *argv[])
  40. "on every invocation.\n");
  41. exit(0);
  42. } else if ( strcmp(prefix, "-p") == 0 ) {
  43. + if (argc != 3) {
  44. + usage();
  45. + exit(1);
  46. + }
  47. prefix = argv[2];
  48. if (strnlen(prefix, PREFIX_MAX_LEN + 1) > PREFIX_MAX_LEN) {
  49. - printf("Error: Prefix cannot exceed %d "
  50. - "characters.\n", PREFIX_MAX_LEN);
  51. + usage();
  52. exit(1);
  53. }
  54. } else {
  55. - printf("\nUsage: iscsi-iname [-h | --help | "
  56. - "-p <prefix>]\n");
  57. + usage();
  58. exit(0);
  59. }
  60. } else {