ubihealthd: Fix options
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/
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.
--- ubi-utils/ubihealthd.c | 1 + 1 file changed, 1 insertion(+)
ubi-utils/ubihealthd.c +1 -0
@@ -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/
PATCH 2/2 ubihealthd: Add option -h/--help
In reply to Alexander DahlUsing '?' 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
@@ -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/
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/
David Oberhollenzer
AppliedApplied to mtd-utils.git master.
Thanks,
David
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/