Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Jul 2019 23:04:26 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r350309 - head/sbin/nvmecontrol
Message-ID:  <201907242304.x6ON4Q3d039732@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Wed Jul 24 23:04:26 2019
New Revision: 350309
URL: https://svnweb.freebsd.org/changeset/base/350309

Log:
  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

Modified:
  head/sbin/nvmecontrol/comnd.c
  head/sbin/nvmecontrol/logpage.c

Modified: head/sbin/nvmecontrol/comnd.c
==============================================================================
--- head/sbin/nvmecontrol/comnd.c	Wed Jul 24 22:57:17 2019	(r350308)
+++ head/sbin/nvmecontrol/comnd.c	Wed Jul 24 23:04:26 2019	(r350309)
@@ -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 
 			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 
 		}
 	}
 	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);
 }
 

Modified: head/sbin/nvmecontrol/logpage.c
==============================================================================
--- head/sbin/nvmecontrol/logpage.c	Wed Jul 24 22:57:17 2019	(r350308)
+++ head/sbin/nvmecontrol/logpage.c	Wed Jul 24 23:04:26 2019	(r350309)
@@ -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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907242304.x6ON4Q3d039732>