From: José Bollo Date: Mon, 21 Oct 2013 10:18:50 +0000 (+0200) Subject: utils/chsmack: fix hazardous option parsing X-Git-Tag: v1.1.0~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18ebc2fe71da94599e45029d7b26144c6bbe7cb4;p=platform%2Fupstream%2Fsmack.git utils/chsmack: fix hazardous option parsing 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] --- diff --git a/utils/chsmack.c b/utils/chsmack.c index b6a731d..1a20c81 100644 --- a/utils/chsmack.c +++ b/utils/chsmack.c @@ -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) {