Don't over-allocate array values in jailparam_export.
Fix a little comment typo. MFC after: 3 days
This commit is contained in:
parent
fa04d5d393
commit
4d02a3e762
@ -719,6 +719,7 @@ jailparam_get(struct jailparam *jp, unsigned njp, int flags)
|
||||
char *
|
||||
jailparam_export(struct jailparam *jp)
|
||||
{
|
||||
size_t *valuelens;
|
||||
char *value, *tvalue, **values;
|
||||
size_t valuelen;
|
||||
int i, nval, ival;
|
||||
@ -740,6 +741,7 @@ jailparam_export(struct jailparam *jp)
|
||||
return (value);
|
||||
}
|
||||
values = alloca(nval * sizeof(char *));
|
||||
valuelens = alloca(nval * sizeof(size_t));
|
||||
valuelen = 0;
|
||||
for (i = 0; i < nval; i++) {
|
||||
switch (jp->jp_ctltype & CTLTYPE) {
|
||||
@ -809,11 +811,12 @@ jailparam_export(struct jailparam *jp)
|
||||
errno = ENOENT;
|
||||
return (NULL);
|
||||
}
|
||||
valuelen += strlen(valbuf) + 1;
|
||||
values[i] = alloca(valuelen);
|
||||
valuelens[i] = strlen(valbuf) + 1;
|
||||
valuelen += valuelens[i];
|
||||
values[i] = alloca(valuelens[i]);
|
||||
strcpy(values[i], valbuf);
|
||||
}
|
||||
value = malloc(valuelen + 1);
|
||||
value = malloc(valuelen);
|
||||
if (value == NULL)
|
||||
strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN);
|
||||
else {
|
||||
@ -821,8 +824,8 @@ jailparam_export(struct jailparam *jp)
|
||||
for (i = 0; i < nval; i++) {
|
||||
strcpy(tvalue, values[i]);
|
||||
if (i < nval - 1) {
|
||||
tvalue += strlen(values[i]);
|
||||
*tvalue++ = ',';
|
||||
tvalue += valuelens[i];
|
||||
tvalue[-1] = ',';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -830,7 +833,7 @@ jailparam_export(struct jailparam *jp)
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the contents of a jail parameter list (but not thst list itself).
|
||||
* Free the contents of a jail parameter list (but not the list itself).
|
||||
*/
|
||||
void
|
||||
jailparam_free(struct jailparam *jp, unsigned njp)
|
||||
|
Loading…
Reference in New Issue
Block a user