Minor argument checking patch
John
jwd at FreeBSD.org
Fri Sep 7 02:10:32 UTC 2012
Hi Folks,
I lost some time recently chasing a bug in a script. Turns
out gstripe (and friends) politely accept a device name as the
label name.
Anyone want to commit, or mind if I commit, a simple change?
# gstripe label -v /dev/multipath/S6[12345678]
gstripe: Invalid label: /dev/multipath/S61
I'd also be willing to say that we should validate that the label
name doesn't exceed sizeof(md.md_name) - currently silently truncated.
Thoughts?
Thanks,
John
Sample patch
--- geom_stripe.c.orig 2012-09-06 21:32:00.000000000 -0400
+++ geom_stripe.c 2012-09-06 21:46:48.000000000 -0400
@@ -136,6 +136,16 @@
hardcode = gctl_get_int(req, "hardcode");
/*
+ * Validate name prior to any device changes
+ */
+ name = gctl_get_ascii(req, "arg0");
+ if (strchr(name,'/') != NULL) {
+ gctl_error(req, "Invalid label: %s", name);
+ return;
+ }
+ strlcpy(md.md_name, name, sizeof(md.md_name));
+
+ /*
* Clear last sector first to spoil all components if device exists.
*/
compsize = 0;
@@ -167,8 +177,6 @@
strlcpy(md.md_magic, G_STRIPE_MAGIC, sizeof(md.md_magic));
md.md_version = G_STRIPE_VERSION;
- name = gctl_get_ascii(req, "arg0");
- strlcpy(md.md_name, name, sizeof(md.md_name));
md.md_id = arc4random();
md.md_all = nargs - 1;
stripesize = gctl_get_intmax(req, "stripesize");
More information about the freebsd-geom
mailing list