summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamie <jamie@FreeBSD.org>2010-08-31 21:50:09 +0000
committerjamie <jamie@FreeBSD.org>2010-08-31 21:50:09 +0000
commit4d14528739b5f059662056b0c92d0e67d618ac39 (patch)
tree13f2dfbcbf89db2cfc047c465cc6cb701c3f1d4e
parentd569ac94f2fbab56ddd0335c70329ce12b174cf2 (diff)
downloadFreeBSD-src-4d14528739b5f059662056b0c92d0e67d618ac39.zip
FreeBSD-src-4d14528739b5f059662056b0c92d0e67d618ac39.tar.gz
Don't over-allocate array values in jailparam_export.
Fix a little comment typo. MFC after: 3 days
-rw-r--r--lib/libjail/jail.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c
index a374563..46da6b4 100644
--- a/lib/libjail/jail.c
+++ b/lib/libjail/jail.c
@@ -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)
OpenPOWER on IntegriCloud