chiark / gitweb /
coredumpctl: add guard to options table
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 30 Oct 2012 08:35:53 +0000 (09:35 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 30 Oct 2012 10:23:59 +0000 (11:23 +0100)
It is not nice to segfault on unknown options :(

src/journal/coredumpctl.c

index 311c18b6ab8d362e48868796d7ed29ab466ae3ef..3560534bf6069618a084e2342ffe6eec68198be4 100644 (file)
@@ -143,10 +143,11 @@ static int parse_argv(int argc, char *argv[]) {
         int r, c;
 
         static const struct option options[] = {
         int r, c;
 
         static const struct option options[] = {
-                { "help",         no_argument,       NULL, 'h'              },
-                { "version" ,     no_argument,       NULL, ARG_VERSION      },
-                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER     },
-                { "output",       required_argument, NULL, 'o'              },
+                { "help",         no_argument,       NULL, 'h'           },
+                { "version" ,     no_argument,       NULL, ARG_VERSION   },
+                { "no-pager",     no_argument,       NULL, ARG_NO_PAGER  },
+                { "output",       required_argument, NULL, 'o'           },
+                { NULL,           0,                 NULL, 0             }
         };
 
         assert(argc >= 0);
         };
 
         assert(argc >= 0);
@@ -183,6 +184,10 @@ static int parse_argv(int argc, char *argv[]) {
                         }
 
                         break;
                         }
 
                         break;
+
+                case '?':
+                        return -EINVAL;
+
                 default:
                         log_error("Unknown option code %c", c);
                         return -EINVAL;
                 default:
                         log_error("Unknown option code %c", c);
                         return -EINVAL;