summaryrefslogtreecommitdiff
path: root/lib/libjail
diff options
context:
space:
mode:
authorJamie Gritton <jamie@FreeBSD.org>2010-08-31 21:50:09 +0000
committerJamie Gritton <jamie@FreeBSD.org>2010-08-31 21:50:09 +0000
commit4d02a3e762285e35921bc27466178623006acacc (patch)
tree13f2dfbcbf89db2cfc047c465cc6cb701c3f1d4e /lib/libjail
parentfa04d5d393f1fe9733cb8dc9c7f66700a28985dc (diff)
downloadsrc-test-4d02a3e762285e35921bc27466178623006acacc.tar.gz
src-test-4d02a3e762285e35921bc27466178623006acacc.zip
Don't over-allocate array values in jailparam_export.
Fix a little comment typo. MFC after: 3 days
Notes
Notes: svn path=/head/; revision=212073
Diffstat (limited to 'lib/libjail')
-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 a3745634dcf19..46da6b49e3f47 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)