Skip to contentSkip to conversation

ubihealthd: Fix options

PATCH Applied Alexander Dahl 3 participants 5 messages Oct 3, 2019 – Oct 7, 2019 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

cover ubihealthd: Fix options

Hello,

I started experimenting with ubihealthd, first thing I did was:

./ubihealthd -h

And boom segfault. The first patch is about that. The second about having the usual -h and --help options.

Greets
Alex

Alexander Dahl (2):
ubihealthd: Add missing sentinel in options array
ubihealthd: Add option -h/--help

 ubi-utils/ubihealthd.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 6 lines
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#1 lore raw

PATCH 1/2 ubihealthd: Add missing sentinel in options array

getopt_long() requires a null terminated array, otherwise we get segfaults when passing invalid options.

Fixes 7f0e2dc21fb2 ("ubi-utils: Implement a ubihealthd")
---
 ubi-utils/ubihealthd.c | 1 +
 1 file changed, 1 insertion(+)
ubi-utils/ubihealthd.c +1 -0
index 3e665be..f38235b 100644
@@ -56,6 +56,7 @@ static const struct option options[] = {
                 .flag = NULL,
                 .val = 'i'
         },
+	{ /* sentinel */ }
 };
 
 static void dolog(const char *fmt, ...)
Signature · 6 lines
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
#2 lore raw

PATCH 2/2 ubihealthd: Add option -h/--help

In reply to Alexander Dahl

Using '?' as option did not work, and would be strange to pass anyway, because it's a glob char for the shell and you would have to escape it like ./ubihealthd -\? … use the more common -h/--help instead.

Note: this does not touch the output, just changes the options itself.

---
 ubi-utils/ubihealthd.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
ubi-utils/ubihealthd.c +8 -2
index f38235b..27799f7 100644
@@ -42,7 +42,7 @@ static int ubi_fd;
 static int interval_secs = 120;
 static int nodaemon;
 
-static const char opt_string[] = "d:i:f";
+static const char opt_string[] = "d:i:fh";
 static const struct option options[] = {
         {
                 .name = "device",
@@ -56,6 +56,12 @@ static const struct option options[] = {
                 .flag = NULL,
                 .val = 'i'
         },
+	{
+		.name = "help",
+		.has_arg = no_argument,
+		.flag = NULL,
+		.val = 'h'
+	},
 	{ /* sentinel */ }
 };
 
@@ -238,7 +244,7 @@ int main (int argc, char *argv[])
 			nodaemon = 1;
 			break;
 		}
-		case '?':
+		case 'h':
 		default:
 			fprintf(stderr, "Usage: %s [ -d UBI_DEVICE ] [-i INTERVAL_SEC ] [ -f ]\n", argv[0]);
 			exit(1);
Signature · 6 lines
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
Acked-by on the v1 series
#3 lore raw
In reply to Alexander Dahl
Quoted 9 lines · Alexander Dahl

Hello,

I started experimenting with ubihealthd, first thing I did was:

./ubihealthd -h

And boom segfault. The first patch is about that. The second about having the usual -h and --help options.

Thanks for fixing this.

Signature · 6 lines
Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/