Skip to content

Commit

Permalink
Terminate the long_options array with an entry that is all zeros,
Browse files Browse the repository at this point in the history
to define end of parsing by getopt_long hence preventing segfault.

Change-Id: I018e5af02e5842d25494b2d93412c8c37dd4b316
Closes-Bug:#1651153
  • Loading branch information
krharsh committed Mar 31, 2017
1 parent 58c8f58 commit d109c09
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions utils/vrfstats.c
Expand Up @@ -127,7 +127,7 @@ static struct option long_options[] = {
[GET_OPT_INDEX] = {"get", required_argument, &get_set, 1},
[DUMP_OPT_INDEX] = {"dump", no_argument, &dump_set, 1},
[HELP_OPT_INDEX] = {"help", no_argument, &help_set, 1},
[MAX_OPT_INDEX] = {"NULL", 0, 0, 0},
[MAX_OPT_INDEX] = {NULL, 0, 0, 0},
};

static void
Expand All @@ -152,8 +152,6 @@ parse_long_opts(int opt_index, char *opt_arg)
switch (opt_index) {
case GET_OPT_INDEX:
vrf = strtol(opt_arg, NULL, 0);
if (errno)
Usage();
stats_op = SANDESH_OP_GET;

break;
Expand All @@ -162,21 +160,22 @@ parse_long_opts(int opt_index, char *opt_arg)
stats_op = SANDESH_OP_DUMP;
break;

case HELP_OPT_INDEX:
default:
Usage();
break;
}


if (errno)
Usage();
return;
}

static void
validate_options(void)
{
int options;

options = get_set + dump_set + help_set;

if (!options)
Usage();

Expand All @@ -191,7 +190,6 @@ main(int argc, char *argv[])
{
char opt;
int ret, option_index;

while (((opt = getopt_long(argc, argv, "",
long_options, &option_index)) >= 0)) {
switch (opt) {
Expand Down

0 comments on commit d109c09

Please sign in to comment.