Fix several related coverity issues:

Make sure to always free shortopts and lopts when returning.
Fix minor logic bug to guard against NULLs properly.

CID: 1403654, 1403656, 1403658
This commit is contained in:
Warner Losh 2019-07-24 23:04:26 +00:00
parent 2b3ac10a27
commit ae5f2ca7b9
2 changed files with 6 additions and 2 deletions

View File

@ -155,7 +155,7 @@ find_long(struct option *lopts, int ch)
for (i = 0; lopts[i].val != ch && lopts[i].name != NULL; i++)
continue;
return i;
return (i);
}
int
@ -251,6 +251,8 @@ arg_parse(int argc, char * const * argv, const struct cmd *f)
if (optind >= argc) {
fprintf(stderr, "Missing arg %s\n", args->descr);
arg_help(argc, argv, f);
free(lopts);
free(shortopts);
return (1);
}
*(char **)args->ptr = argv[optind++];
@ -258,10 +260,12 @@ arg_parse(int argc, char * const * argv, const struct cmd *f)
}
}
free(lopts);
free(shortopts);
return (0);
bad_arg:
fprintf(stderr, "Bad value to --%s: %s\n", opts[idx].long_arg, optarg);
free(lopts);
free(shortopts);
exit(1);
}

View File

@ -465,7 +465,7 @@ logpage(const struct cmd *f, int argc, char *argv[])
* unless the vendors match.
*/
SLIST_FOREACH(lpf, &logpages, link) {
if (lpf->vendor != NULL && vendor != NULL &&
if (lpf->vendor == NULL || vendor == NULL ||
strcmp(lpf->vendor, vendor) != 0)
continue;
if (opt.page != lpf->log_page)