Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Nov 2008 19:13:58 +0000 (UTC)
From:      Ulf Lilleengen <lulf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r185309 - head/sys/geom/vinum
Message-ID:  <200811251913.mAPJDwrD032237@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: lulf
Date: Tue Nov 25 19:13:58 2008
New Revision: 185309
URL: http://svn.freebsd.org/changeset/base/185309

Log:
  - Fix a potential NULL pointer reference. Note that this cannot happen in
    practice, but it is a good programming practice nontheless and it allows the
    kernel to not depend on userland correctness.
  
  Found with:   Coverity Prevent(tm)
  CID:          655-659, 664-667

Modified:
  head/sys/geom/vinum/geom_vinum.c
  head/sys/geom/vinum/geom_vinum_list.c
  head/sys/geom/vinum/geom_vinum_move.c
  head/sys/geom/vinum/geom_vinum_rename.c
  head/sys/geom/vinum/geom_vinum_rm.c

Modified: head/sys/geom/vinum/geom_vinum.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum.c	Tue Nov 25 19:06:20 2008	(r185308)
+++ head/sys/geom/vinum/geom_vinum.c	Tue Nov 25 19:13:58 2008	(r185309)
@@ -165,12 +165,20 @@ gv_create(struct g_geom *gp, struct gctl
 	plexes = gctl_get_paraml(req, "plexes", sizeof(*plexes));
 	subdisks = gctl_get_paraml(req, "subdisks", sizeof(*subdisks));
 	drives = gctl_get_paraml(req, "drives", sizeof(*drives));
+	if (volumes == NULL || plexes == NULL || subdisks == NULL ||
+	    drives == NULL) {
+		gctl_error(req, "number of objects not given");
+		return (-1);
+	}
 
 	/* First, handle drive definitions ... */
 	for (i = 0; i < *drives; i++) {
 		snprintf(buf, sizeof(buf), "drive%d", i);
 		d2 = gctl_get_paraml(req, buf, sizeof(*d2));
-
+		if (d2 == NULL) {
+			gctl_error(req, "no drive definition given");
+			return (-1);
+		}
 		d = gv_find_drive(sc, d2->name);
 		if (d != NULL) {
 			gctl_error(req, "drive '%s' is already known",
@@ -205,7 +213,10 @@ gv_create(struct g_geom *gp, struct gctl
 		error = 0;
 		snprintf(buf, sizeof(buf), "volume%d", i);
 		v2 = gctl_get_paraml(req, buf, sizeof(*v2));
-
+		if (v2 == NULL) {
+			gctl_error(req, "no volume definition given");
+			return (-1);
+		}
 		v = gv_find_vol(sc, v2->name);
 		if (v != NULL) {
 			gctl_error(req, "volume '%s' is already known",
@@ -226,7 +237,10 @@ gv_create(struct g_geom *gp, struct gctl
 		error = 0;
 		snprintf(buf, sizeof(buf), "plex%d", i);
 		p2 = gctl_get_paraml(req, buf, sizeof(*p2));
-
+		if (p2 == NULL) {
+			gctl_error(req, "no plex definition given");
+			return (-1);
+		}
 		p = gv_find_plex(sc, p2->name);
 		if (p != NULL) {
 			gctl_error(req, "plex '%s' is already known", p->name);
@@ -260,7 +274,10 @@ gv_create(struct g_geom *gp, struct gctl
 		error = 0;
 		snprintf(buf, sizeof(buf), "sd%d", i);
 		s2 = gctl_get_paraml(req, buf, sizeof(*s2));
-
+		if (s2 == NULL) {
+			gctl_error(req, "no subdisk definition given");
+			return (-1);
+		}
 		s = gv_find_sd(sc, s2->name);
 		if (s != NULL) {
 			gctl_error(req, "subdisk '%s' is already known",
@@ -405,7 +422,10 @@ gv_config(struct gctl_req *req, struct g
 	/* Return configuration in string form. */
 	} else if (!strcmp(verb, "getconfig")) {
 		comment = gctl_get_param(req, "comment", NULL);
-
+		if (comment == NULL) {
+			gctl_error(req, "no comment parameter given");
+			return;
+		}
 		sb = sbuf_new(NULL, NULL, GV_CFG_LEN, SBUF_FIXEDLEN);
 		gv_format_config(sc, sb, 0, comment);
 		sbuf_finish(sb);

Modified: head/sys/geom/vinum/geom_vinum_list.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum_list.c	Tue Nov 25 19:06:20 2008	(r185308)
+++ head/sys/geom/vinum/geom_vinum_list.c	Tue Nov 25 19:13:58 2008	(r185309)
@@ -62,6 +62,10 @@ gv_list(struct g_geom *gp, struct gctl_r
 	}
 
 	flags = gctl_get_paraml(req, "flags", sizeof(*flags));
+	if (flags == NULL) {
+		gctl_error(req, "no flags given");
+		return;
+	}
 
 	sc = gp->softc;
 
@@ -69,6 +73,10 @@ gv_list(struct g_geom *gp, struct gctl_r
 
 	/* Figure out which command was given. */
 	cmd = gctl_get_param(req, "cmd", NULL);
+	if (cmd == NULL) {
+		gctl_error(req, "no command given");
+		return;
+	}
 
 	/* List specific objects or everything. */
 	if (!strcmp(cmd, "list") || !strcmp(cmd, "l")) {

Modified: head/sys/geom/vinum/geom_vinum_move.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum_move.c	Tue Nov 25 19:06:20 2008	(r185308)
+++ head/sys/geom/vinum/geom_vinum_move.c	Tue Nov 25 19:13:58 2008	(r185309)
@@ -56,7 +56,15 @@ gv_move(struct g_geom *gp, struct gctl_r
 	sc = gp->softc;
 
 	argc = gctl_get_paraml(req, "argc", sizeof(*argc));
+	if (argc == NULL) {
+		gctl_error(req, "no arguments given");
+		return;
+	}
 	flags = gctl_get_paraml(req, "flags", sizeof(*flags));
+	if (flags == NULL) {
+		gctl_error(req, "no flags given");
+		return;
+	}
 	destination = gctl_get_param(req, "destination", NULL);
 	if (destination == NULL) {
 		gctl_error(req, "no destination given");

Modified: head/sys/geom/vinum/geom_vinum_rename.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum_rename.c	Tue Nov 25 19:06:20 2008	(r185308)
+++ head/sys/geom/vinum/geom_vinum_rename.c	Tue Nov 25 19:13:58 2008	(r185309)
@@ -65,6 +65,10 @@ gv_rename(struct g_geom *gp, struct gctl
 	sc = gp->softc;
 
 	flags = gctl_get_paraml(req, "flags", sizeof(*flags));
+	if (flags == NULL) {
+		gctl_error(req, "no flags given");
+		return;
+	}
 
 	newname = gctl_get_param(req, "newname", NULL);
 	if (newname == NULL) {

Modified: head/sys/geom/vinum/geom_vinum_rm.c
==============================================================================
--- head/sys/geom/vinum/geom_vinum_rm.c	Tue Nov 25 19:06:20 2008	(r185308)
+++ head/sys/geom/vinum/geom_vinum_rm.c	Tue Nov 25 19:13:58 2008	(r185309)
@@ -59,13 +59,18 @@ gv_remove(struct g_geom *gp, struct gctl
 	int i, type, err;
 
 	argc = gctl_get_paraml(req, "argc", sizeof(*argc));
-	flags = gctl_get_paraml(req, "flags", sizeof(*flags));
 
 	if (argc == NULL || *argc == 0) {
 		gctl_error(req, "no arguments given");
 		return;
 	}
 
+	flags = gctl_get_paraml(req, "flags", sizeof(*flags));
+	if (flags == NULL) {
+		gctl_error(req, "no flags given");
+		return;
+	}
+
 	sc = gp->softc;
 
 	for (i = 0; i < *argc; i++) {



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