Remove the use of nvlist_.*[vf] functions from casper and replace

them with snprintf(3). Assert the results of snprintf(3).

Approved by:	pjd (mentor)
This commit is contained in:
Mariusz Zaborski 2015-04-29 22:33:53 +00:00
parent bed3fb70df
commit 256b83ab83
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=282253
2 changed files with 22 additions and 8 deletions

View File

@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/in.h>
#include <assert.h>
#include <errno.h>
#include <netdb.h>
#include <stdlib.h>
@ -103,6 +104,8 @@ static void
hostent_pack(const struct hostent *hp, nvlist_t *nvl)
{
unsigned int ii;
char nvlname[64];
int n;
nvlist_add_string(nvl, "name", hp->h_name);
nvlist_add_number(nvl, "addrtype", (uint64_t)hp->h_addrtype);
@ -112,8 +115,9 @@ hostent_pack(const struct hostent *hp, nvlist_t *nvl)
nvlist_add_number(nvl, "naliases", 0);
} else {
for (ii = 0; hp->h_aliases[ii] != NULL; ii++) {
nvlist_addf_string(nvl, hp->h_aliases[ii], "alias%u",
ii);
n = snprintf(nvlname, sizeof(nvlname), "alias%u", ii);
assert(n > 0 && n < (int)sizeof(nvlname));
nvlist_add_string(nvl, nvlname, hp->h_aliases[ii]);
}
nvlist_add_number(nvl, "naliases", (uint64_t)ii);
}
@ -122,8 +126,10 @@ hostent_pack(const struct hostent *hp, nvlist_t *nvl)
nvlist_add_number(nvl, "naddrs", 0);
} else {
for (ii = 0; hp->h_addr_list[ii] != NULL; ii++) {
nvlist_addf_binary(nvl, hp->h_addr_list[ii],
(size_t)hp->h_length, "addr%u", ii);
n = snprintf(nvlname, sizeof(nvlname), "addr%u", ii);
assert(n > 0 && n < (int)sizeof(nvlname));
nvlist_add_binary(nvl, nvlname, hp->h_addr_list[ii],
(size_t)hp->h_length);
}
nvlist_add_number(nvl, "naddrs", (uint64_t)ii);
}
@ -271,9 +277,10 @@ dns_getaddrinfo(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
{
struct addrinfo hints, *hintsp, *res, *cur;
const char *hostname, *servname;
char nvlname[64];
nvlist_t *elem;
unsigned int ii;
int error, family;
int error, family, n;
if (!dns_allowed_type(limits, "ADDR"))
return (NO_RECOVERY);
@ -310,7 +317,9 @@ dns_getaddrinfo(const nvlist_t *limits, const nvlist_t *nvlin, nvlist_t *nvlout)
for (cur = res, ii = 0; cur != NULL; cur = cur->ai_next, ii++) {
elem = addrinfo_pack(cur);
nvlist_movef_nvlist(nvlout, elem, "res%u", ii);
n = snprintf(nvlname, sizeof(nvlname), "res%u", ii);
assert(n > 0 && n < (int)sizeof(nvlname));
nvlist_move_nvlist(nvlout, nvlname, elem);
}
freeaddrinfo(res);

View File

@ -30,6 +30,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <assert.h>
#include <errno.h>
#include <grp.h>
#include <stdlib.h>
@ -184,6 +185,8 @@ grp_allowed_fields(const nvlist_t *oldlimits, const nvlist_t *newlimits)
static bool
grp_pack(const nvlist_t *limits, const struct group *grp, nvlist_t *nvl)
{
char nvlname[64];
int n;
if (grp == NULL)
return (true);
@ -210,8 +213,10 @@ grp_pack(const nvlist_t *limits, const struct group *grp, nvlist_t *nvl)
unsigned int ngroups;
for (ngroups = 0; grp->gr_mem[ngroups] != NULL; ngroups++) {
nvlist_addf_string(nvl, grp->gr_mem[ngroups],
"gr_mem[%u]", ngroups);
n = snprintf(nvlname, sizeof(nvlname), "gr_mem[%u]",
ngroups);
assert(n > 0 && n < sizeof(nvlname));
nvlist_add_string(nvl, nvlname, grp->gr_mem[ngroups]);
}
nvlist_add_number(nvl, "gr_nmem", (uint64_t)ngroups);
}