diff options
author | lulf <lulf@FreeBSD.org> | 2008-11-25 19:13:58 +0000 |
---|---|---|
committer | lulf <lulf@FreeBSD.org> | 2008-11-25 19:13:58 +0000 |
commit | 7e02db46fdabf2476c22a9497beb7526fc77191a (patch) | |
tree | 4d1447a61493af5cc9ecf254416df9e3856a4a7d /sys/geom/vinum | |
parent | 8421b814bc09926c4aa2ce04bbbe433186cddcab (diff) | |
download | FreeBSD-src-7e02db46fdabf2476c22a9497beb7526fc77191a.zip FreeBSD-src-7e02db46fdabf2476c22a9497beb7526fc77191a.tar.gz |
- 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
Diffstat (limited to 'sys/geom/vinum')
-rw-r--r-- | sys/geom/vinum/geom_vinum.c | 30 | ||||
-rw-r--r-- | sys/geom/vinum/geom_vinum_list.c | 8 | ||||
-rw-r--r-- | sys/geom/vinum/geom_vinum_move.c | 8 | ||||
-rw-r--r-- | sys/geom/vinum/geom_vinum_rename.c | 4 | ||||
-rw-r--r-- | sys/geom/vinum/geom_vinum_rm.c | 7 |
5 files changed, 51 insertions, 6 deletions
diff --git a/sys/geom/vinum/geom_vinum.c b/sys/geom/vinum/geom_vinum.c index e275ead..1a915ed 100644 --- a/sys/geom/vinum/geom_vinum.c +++ b/sys/geom/vinum/geom_vinum.c @@ -165,12 +165,20 @@ gv_create(struct g_geom *gp, struct gctl_req *req) 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_req *req) 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_req *req) 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_req *req) 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_class *mp, char const *verb) /* 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); diff --git a/sys/geom/vinum/geom_vinum_list.c b/sys/geom/vinum/geom_vinum_list.c index cb4ccfa..b1a668f 100644 --- a/sys/geom/vinum/geom_vinum_list.c +++ b/sys/geom/vinum/geom_vinum_list.c @@ -62,6 +62,10 @@ gv_list(struct g_geom *gp, struct gctl_req *req) } 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_req *req) /* 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")) { diff --git a/sys/geom/vinum/geom_vinum_move.c b/sys/geom/vinum/geom_vinum_move.c index 9a22684..04822bc 100644 --- a/sys/geom/vinum/geom_vinum_move.c +++ b/sys/geom/vinum/geom_vinum_move.c @@ -56,7 +56,15 @@ gv_move(struct g_geom *gp, struct gctl_req *req) 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"); diff --git a/sys/geom/vinum/geom_vinum_rename.c b/sys/geom/vinum/geom_vinum_rename.c index 50501d2..ee5fc9c 100644 --- a/sys/geom/vinum/geom_vinum_rename.c +++ b/sys/geom/vinum/geom_vinum_rename.c @@ -65,6 +65,10 @@ gv_rename(struct g_geom *gp, struct gctl_req *req) 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) { diff --git a/sys/geom/vinum/geom_vinum_rm.c b/sys/geom/vinum/geom_vinum_rm.c index 3785cfa..d7748da 100644 --- a/sys/geom/vinum/geom_vinum_rm.c +++ b/sys/geom/vinum/geom_vinum_rm.c @@ -59,13 +59,18 @@ gv_remove(struct g_geom *gp, struct gctl_req *req) 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++) { |