Fix the construction of the gctl_req that got broken by my

previous commit and that introduced optional parameters.
Existing classes (like geli(8)) use empty strings by default
and expect the parameter to be passed to the kernel as such.
Also, the default value of a string argument can be NULL.
Fix both cases by making the optional parameter conditional
upon gc_argname being set and making sure to test for NULL
before dereferencing the pointer.

Reported by: brueffer@
This commit is contained in:
Marcel Moolenaar 2007-05-17 15:34:51 +00:00
parent c6b342f820
commit cf805fab87
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=169659

View File

@ -330,7 +330,9 @@ parse_arguments(struct g_command *cmd, struct gctl_req *req, int *argc,
gctl_ro_param(req, opt->go_name,
sizeof(intmax_t), opt->go_val);
} else if (G_OPT_TYPE(opt) == G_TYPE_STRING) {
if (*(char *)opt->go_val != '\0')
if (cmd->gc_argname == NULL ||
opt->go_val == NULL ||
*(char *)opt->go_val != '\0')
gctl_ro_param(req, opt->go_name,
-1, opt->go_val);
} else {