Don't copy and return a potentially unset buffer when jail_get fails.

This commit is contained in:
Jamie Gritton 2010-07-15 19:21:33 +00:00
parent c26c472cc8
commit fba36ac4de
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210134

View File

@ -94,11 +94,15 @@ jail_getname(int jid)
jiov[5].iov_len = JAIL_ERRMSGLEN;
jail_errmsg[0] = 0;
jid = jail_get(jiov, 6, 0);
if (jid < 0 && !jail_errmsg[0])
snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s",
strerror(errno));
name = strdup(namebuf);
if (name == NULL)
strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN);
if (jid < 0) {
if (!jail_errmsg[0])
snprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s",
strerror(errno));
return NULL;
} else {
name = strdup(namebuf);
if (name == NULL)
strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN);
}
return name;
}