return is correctly handled.
Thanks to Tobias Stoeckmann.
return NULL;
}
-size_t
+ssize_t
dhcp_vendor(char *str, size_t len)
{
struct utsname utn;
int l;
if (uname(&utn) != 0)
- return (size_t)snprintf(str, len, "%s-%s",
+ return (ssize_t)snprintf(str, len, "%s-%s",
PACKAGE, VERSION);
p = str;
l = snprintf(p, len,
"%s-%s:%s-%s:%s", PACKAGE, VERSION,
utn.sysname, utn.release, utn.machine);
+ if (l == -1 || (size_t)(l + 1) > len)
+ return -1;
p += l;
len -= (size_t)l;
l = if_machinearch(p, len);
+ if (l == -1 || (size_t)(l + 1) > len)
+ return -1;
p += l;
- return (size_t)(p - str);
+ return p - str;
}
int
struct dhcp_opt *vivso_find(uint32_t, const void *);
-size_t dhcp_vendor(char *, size_t);
+ssize_t dhcp_vendor(char *, size_t);
#define add_option_mask(var, val) (var[val >> 3] |= 1 << (val & 7))
#define del_option_mask(var, val) (var[val >> 3] &= ~(1 << (val & 7)))
p += ifo->vendorclassid[0] + 1;
}
-
if (type != DHCP_INFORM) {
if (ifo->leasetime != 0) {
*p++ = DHO_LEASETIME;
dhcp6_makevendor(struct dhcp6_option *o, const struct interface *ifp)
{
const struct if_options *ifo;
- size_t len;
+ size_t len, i;
uint8_t *p;
uint16_t u16;
uint32_t u32;
- size_t vlen, i;
+ ssize_t vlen;
const struct vivco *vivco;
char vendor[VENDORCLASSID_MAX_LEN];
vlen = 0; /* silence bogus gcc warning */
} else {
vlen = dhcp_vendor(vendor, sizeof(vendor));
- len += sizeof(uint16_t) + vlen;
+ if (vlen == -1)
+ vlen = 0;
+ else
+ len += sizeof(uint16_t) + (size_t)vlen;
}
if (len > UINT16_MAX) {
memcpy(p, vivco->data, vivco->len);
p += vivco->len;
}
- } else {
+ } else if (vlen) {
u16 = htons(vlen);
memcpy(p, &u16, sizeof(u16));
p += sizeof(u16);
- memcpy(p, vendor, vlen);
+ memcpy(p, vendor, (size_t)vlen);
}
}
FILE *fp;
char *line, *buf, *option, *p;
size_t buflen;
+ ssize_t vlen;
int skip = 0, have_profile = 0;
#ifndef EMBEDDED_CONFIG
const char * const *e;
ifo->auth.options |= DHCPCD_AUTH_REQUIRE;
TAILQ_INIT(&ifo->auth.tokens);
- ifo->vendorclassid[0] =
- (uint8_t)dhcp_vendor((char *)ifo->vendorclassid + 1,
- sizeof(ifo->vendorclassid) - 1);
+ vlen = dhcp_vendor((char *)ifo->vendorclassid + 1,
+ sizeof(ifo->vendorclassid) - 1);
+ ifo->vendorclassid[0] = vlen == -1 ? 0 : (uint8_t)vlen;
buf = NULL;
buflen = 0;