summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshogbo <oshogbo@FreeBSD.org>2015-04-29 22:33:53 +0000
committeroshogbo <oshogbo@FreeBSD.org>2015-04-29 22:33:53 +0000
commitcc50a2704d8c9871c97112d02428f73508f6d41d (patch)
treea1a34ac5d32799b1963768f62267232b2002efe6
parent9e1c4e0e6238ad9d9b7d529bd59d67bb2a179741 (diff)
downloadFreeBSD-src-cc50a2704d8c9871c97112d02428f73508f6d41d.zip
FreeBSD-src-cc50a2704d8c9871c97112d02428f73508f6d41d.tar.gz
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)
-rw-r--r--libexec/casper/dns/dns.c21
-rw-r--r--libexec/casper/grp/grp.c9
2 files changed, 22 insertions, 8 deletions
diff --git a/libexec/casper/dns/dns.c b/libexec/casper/dns/dns.c
index c5f03ad..f82801e 100644
--- a/libexec/casper/dns/dns.c
+++ b/libexec/casper/dns/dns.c
@@ -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);
diff --git a/libexec/casper/grp/grp.c b/libexec/casper/grp/grp.c
index ba22f62..ab28e1a 100644
--- a/libexec/casper/grp/grp.c
+++ b/libexec/casper/grp/grp.c
@@ -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);
}
OpenPOWER on IntegriCloud