utils/chsmack: fix hazardous option parsing
authorJosé Bollo <jose.bollo@eurogiciel.fr>
Mon, 21 Oct 2013 10:18:50 +0000 (12:18 +0200)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 23 Oct 2013 05:41:32 +0000 (08:41 +0300)
The variable option_index was only set to a proper value if the
given option is a long option. There was also exit() missing on
error condition if SMACK label was invalid.

This patch removes option_index, parameter name from corresponding
error message and adds exit() call when the error condition
realizes.

[jarkko.sakkinen@linux.intel.com: rewrote patch description]
(cherry picked from commit 18ebc2fe71da94599e45029d7b26144c6bbe7cb4)

utils/chsmack.c

index b6a731d..1a20c81 100644 (file)
@@ -48,20 +48,19 @@ int main(int argc, char *argv[])
 
        int transmute_flag = 0;
        int option_flag = 0;
-       int option_index;
        int rc;
        int c;
        int i;
 
        while ((c = getopt_long(argc, argv, "a:e:m:t", long_options,
-                               &option_index)) != -1) {
+                               NULL)) != -1) {
                if ((c == 'a' || c == 'e' || c == 'm')
                    && strnlen(optarg, SMACK_LABEL_LEN + 1)
                       == (SMACK_LABEL_LEN + 1)) {
-                       fprintf(stderr, "%s label \"%s\" "
+                       fprintf(stderr, "label \"%s\" "
                                        "exceeds %d characters.\n",
-                               long_options[option_index].name, optarg,
-                               SMACK_LABEL_LEN);
+                               optarg, SMACK_LABEL_LEN);
+                       exit(1);
                }
 
                switch (c) {