#define ARP_LEN \
(sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
-static int
+static ssize_t
arp_send(const struct interface *ifp, int op, in_addr_t sip, in_addr_t tip)
{
uint8_t arp_buffer[ARP_LEN];
ar.ar_op = htons(op);
p = arp_buffer;
- len = sizeof(arp_buffer);
+ len = 0;
#define CHECK(fun, b, l) \
do { \
- if (len < (l)) \
+ if (len + (l) > sizeof(arp_buffer)) \
goto eexit; \
fun(p, (b), (l)); \
p += (l); \
- len -= (l); \
+ len += (l); \
} while (/* CONSTCOND */ 0)
#define APPEND(b, l) CHECK(memcpy, b, l)
#define ZERO(l) CHECK(memset, 0, l)
APPEND(&sip, sizeof(sip));
ZERO(ifp->hwlen);
APPEND(&tip, sizeof(tip));
- len = p - arp_buffer;
return ipv4_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
eexit:
{
return (uint64_t)htonl((uint32_t)(x >> 32)) |
- (int64_t)htonl((uint32_t)(x & 0xffffffff)) << 32;
+ (uint64_t)htonl((uint32_t)(x & 0xffffffff)) << 32;
}
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
#define htonll(x) (x)
{
return (uint64_t)ntohl((uint32_t)(x >> 32)) |
- (int64_t)ntohl((uint32_t)(x & 0xffffffff)) << 32;
+ (uint64_t)ntohl((uint32_t)(x & 0xffffffff)) << 32;
}
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
#define ntohll(x) (x)
*/
const struct token *
dhcp_auth_validate(struct authstate *state, const struct auth *auth,
- const uint8_t *m, unsigned int mlen, int mp, int mt,
- const uint8_t *data, unsigned int dlen)
+ const uint8_t *m, size_t mlen, int mp, int mt,
+ const uint8_t *data, size_t dlen)
{
uint8_t protocol, algorithm, rdm, *mm, type;
uint64_t replay;
uint32_t secretid;
const uint8_t *d, *realm;
- unsigned int realm_len;
+ size_t realm_len;
const struct token *t;
time_t now;
uint8_t hmac[HMAC_LENGTH];
return rdm;
}
-#define JAN_1970 2208988800UL /* 1970 - 1900 in seconds */
+#define JAN_1970 2208988800U /* 1970 - 1900 in seconds */
static uint64_t
get_next_rdm_monotonic_clock(struct auth *auth)
{
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
return ++auth->last_replay; /* report error? */
pack[0] = htonl((uint32_t)ts.tv_sec + JAN_1970);
- frac = (ts.tv_nsec / 1e9 * 0x100000000ULL);
+ frac = ((double)ts.tv_nsec / 1e9 * 0x100000000ULL);
pack[1] = htonl((uint32_t)frac);
memcpy(&rdm, &pack, sizeof(rdm));
* mt is the DHCP message type.
* data and dlen refer to the authentication option within the message.
*/
-int
+ssize_t
dhcp_auth_encode(struct auth *auth, const struct token *t,
- uint8_t *m, unsigned int mlen, int mp, int mt,
- uint8_t *data, unsigned int dlen)
+ uint8_t *m, size_t mlen, int mp, int mt,
+ uint8_t *data, size_t dlen)
{
uint64_t rdm;
uint8_t hmac[HMAC_LENGTH];
dlen += sizeof(t->secretid) + sizeof(hmac);
break;
}
- return dlen;
+ return (ssize_t)dlen;
}
if (dlen < 1 + 1 + 1 + 8) {
return -1;
}
memcpy(data, t->key, t->key_len);
- return dlen - t->key_len;
+ return (ssize_t)(dlen - t->key_len);
}
/* DISCOVER or INFORM messages don't write auth info */
if (!info)
- return dlen;
+ return (ssize_t)dlen;
/* Loading a saved lease without an authentication option */
if (t == NULL)
}
/* Done! */
- return dlen - sizeof(hmac); /* should be zero */
+ return (int)(dlen - sizeof(hmac)); /* should be zero */
}
struct token {
TAILQ_ENTRY(token) next;
uint32_t secretid;
- unsigned int realm_len;
+ size_t realm_len;
unsigned char *realm;
- unsigned int key_len;
+ size_t key_len;
unsigned char *key;
time_t expire;
};
const struct token * dhcp_auth_validate(struct authstate *,
const struct auth *,
- const uint8_t *, unsigned int, int, int,
- const uint8_t *, unsigned int);
+ const uint8_t *, size_t, int, int,
+ const uint8_t *, size_t);
-int dhcp_auth_encode(struct auth *, const struct token *,
- uint8_t *, unsigned int, int, int,
- uint8_t *, unsigned int);
+ssize_t dhcp_auth_encode(struct auth *, const struct token *,
+ uint8_t *, size_t, int, int,
+ uint8_t *, size_t);
#endif
struct dhcp_state *state;
int fd = -1;
struct ifreq ifr;
- int buf_len = 0;
+ int ibuf_len = 0;
+ size_t buf_len;
struct bpf_version pv;
struct bpf_program pf;
#ifdef BIOCIMMEDIATE
goto eexit;
/* Get the required BPF buffer length from the kernel. */
- if (ioctl(fd, BIOCGBLEN, &buf_len) == -1)
+ if (ioctl(fd, BIOCGBLEN, &ibuf_len) == -1)
goto eexit;
- if (state->buffer_size != (size_t)buf_len) {
+ buf_len = (size_t)ibuf_len;
+ if (state->buffer_size != buf_len) {
free(state->buffer);
state->buffer = malloc(buf_len);
if (state->buffer == NULL)
ssize_t
ipv4_sendrawpacket(const struct interface *ifp, int protocol,
- const void *data, ssize_t len)
+ const void *data, size_t len)
{
struct iovec iov[2];
struct ether_header hw;
* So we pass the buffer in the API so we can loop on >1 packet. */
ssize_t
ipv4_getrawpacket(struct interface *ifp, int protocol,
- void *data, ssize_t len, int *partialcsum)
+ void *data, size_t len, int *partialcsum)
{
int fd = -1;
struct bpf_hdr packet;
return errno == EAGAIN ? 0 : -1;
else if ((size_t)bytes < sizeof(packet))
return -1;
- state->buffer_len = bytes;
+ state->buffer_len = (size_t)bytes;
state->buffer_pos = 0;
}
bytes = -1;
goto next; /* Packet beyond buffer, drop. */
payload = state->buffer + state->buffer_pos +
packet.bh_hdrlen + ETHER_HDR_LEN;
- bytes = packet.bh_caplen - ETHER_HDR_LEN;
- if (bytes > len)
- bytes = len;
- memcpy(data, payload, bytes);
+ bytes = (ssize_t)packet.bh_caplen - ETHER_HDR_LEN;
+ if ((size_t)bytes > len)
+ bytes = (ssize_t)len;
+ memcpy(data, payload, (size_t)bytes);
next:
state->buffer_pos += BPF_WORDALIGN(packet.bh_hdrlen +
packet.bh_caplen);
else
snprintf(**e, len, "%s=%s", var, value);
(*e)++;
- return len;
+ return (ssize_t)len;
}
ssize_t
-setvard(char ***e, const char *prefix, const char *var, int value)
+setvard(char ***e, const char *prefix, const char *var, size_t value)
{
char buffer[32];
- snprintf(buffer, sizeof(buffer), "%d", value);
+ snprintf(buffer, sizeof(buffer), "%zu", value);
return setvar(e, prefix, var, buffer);
}
#define STRINGIFY(a) #a
#define TOSTRING(a) STRINGIFY(a)
-#define timeval_to_double(tv) ((tv)->tv_sec * 1.0 + (tv)->tv_usec * 1.0e-6)
+#define timeval_to_double(tv) \
+ ((double)(tv)->tv_sec + (double)((tv)->tv_usec) * 1.0e-6)
#define timernorm(tv) do { \
while ((tv)->tv_usec >= 1000000) { \
(tv)->tv_sec++; \
ms = (tv)->tv_sec * 1000; \
ms += (tv)->tv_usec / 1000; \
} while (0 /* CONSTCOND */);
-#define ms_to_tv(tv, ms) do { \
- (tv)->tv_sec = ms / 1000; \
- (tv)->tv_usec = (ms - ((tv)->tv_sec * 1000)) * 1000; \
+#define ms_to_tv(tv, ms) do { \
+ (tv)->tv_sec = ms / 1000; \
+ (tv)->tv_usec = (suseconds_t)(ms - ((tv)->tv_sec * 1000)) * 1000; \
} while (0 /* CONSTCOND */);
#ifndef TIMEVAL_TO_TIMESPEC
extern int clock_monotonic;
int get_monotonic(struct timeval *);
ssize_t setvar(char ***, const char *, const char *, const char *);
-ssize_t setvard(char ***, const char *, const char *, int);
+ssize_t setvard(char ***, const char *, const char *, size_t);
time_t uptime(void);
#endif
int
closefrom(int fd)
{
- int i, max, r;
+ long max;
+ int i, r;
#ifdef _SC_OPEN_MAX
max = sysconf(_SC_OPEN_MAX);
max = getdtablesize();
#endif
r = 0;
- for (i = fd; i < max; i++)
- r += close(i);
+ for (i = fd; i < max; i++) {
+ if (close(i) == -1)
+ r = -1;
+ }
return r;
}
while (*src++);
}
- return src - s - 1;
+
+ return (size_t)(src - s - 1);
}
CFLAGS+= -Winline -Wwrite-strings -Wcast-align -Wcast-qual
CFLAGS+= -Wpointer-arith -Wstrict-overflow
CFLAGS+= -Wdeclaration-after-statement
+CFLAGS+= -Wconversion
EOF
case "$OS" in
- openbsd*) ;; # OpenBSD has many redundant decs in system headers
+ mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
*) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK;;
esac
fi
close(fd);
}
-static int
+static socklen_t
make_sock(struct dhcpcd_ctx *ctx, struct sockaddr_un *sun, const char *ifname)
{
#ifdef SOCK_CLOEXEC
if ((ctx->control_fd = socket(AF_UNIX,
SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1)
- return -1;
+ return 0;
#else
int flags;
if ((ctx->control_fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
- return -1;
+ return 0;
if ((flags = fcntl(ctx->control_fd, F_GETFD, 0)) == -1 ||
fcntl(ctx->control_fd, F_SETFD, flags | FD_CLOEXEC) == -1)
{
close(ctx->control_fd);
ctx->control_fd = -1;
- return -1;
+ return 0;
}
if ((flags = fcntl(ctx->control_fd, F_GETFL, 0)) == -1 ||
fcntl(ctx->control_fd, F_SETFL, flags | O_NONBLOCK) == -1)
{
close(ctx->control_fd);
ctx->control_fd = -1;
- return -1;
+ return 0;
}
#endif
memset(sun, 0, sizeof(*sun));
control_start(struct dhcpcd_ctx *ctx, const char *ifname)
{
struct sockaddr_un sun;
- int len;
+ socklen_t len;
- if ((len = make_sock(ctx, &sun, ifname)) == -1)
+ if ((len = make_sock(ctx, &sun, ifname)) == 0)
return -1;
unlink(ctx->control_sock);
if (bind(ctx->control_fd, (struct sockaddr *)&sun, len) == -1 ||
control_open(struct dhcpcd_ctx *ctx, const char *ifname)
{
struct sockaddr_un sun;
- int len;
+ socklen_t len;
- if ((len = make_sock(ctx, &sun, ifname)) == -1)
+ if ((len = make_sock(ctx, &sun, ifname)) == 0)
return -1;
if (connect(ctx->control_fd, (struct sockaddr *)&sun, len) == -1) {
close(ctx->control_fd);
return 0;
}
-int
+ssize_t
control_send(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
{
- char buffer[1024], *p;
+ char buffer[1024];
int i;
- size_t len;
+ size_t len, l;
if (argc > 255) {
errno = ENOBUFS;
return -1;
}
- p = buffer;
+ len = 0;
for (i = 0; i < argc; i++) {
- len = strlen(argv[i]) + 1;
- if ((p - buffer) + len > sizeof(buffer)) {
+ l = strlen(argv[i]) + 1;
+ if (len + l > sizeof(buffer)) {
errno = ENOBUFS;
return -1;
}
- memcpy(p, argv[i], len);
- p += len;
+ memcpy(buffer + len, argv[i], l);
+ len += l;
}
- return write(ctx->control_fd, buffer, p - buffer);
+ return write(ctx->control_fd, buffer, len);
}
void
int control_start(struct dhcpcd_ctx *, const char *);
int control_stop(struct dhcpcd_ctx *);
int control_open(struct dhcpcd_ctx *, const char *);
-int control_send(struct dhcpcd_ctx *, int, char * const *);
+ssize_t control_send(struct dhcpcd_ctx *, int, char * const *);
void control_close(struct dhcpcd_ctx *ctx);
#endif
#ifndef CRYPT_H
#define CRYPT_H
-void hmac_md5(const uint8_t *, int, const uint8_t *, int, uint8_t *);
+void hmac_md5(const uint8_t *, size_t, const uint8_t *, size_t, uint8_t *);
#endif
/* hmac_md5 as per RFC3118 */
void
-hmac_md5(const uint8_t *text, int text_len,
- const uint8_t *key, int key_len,
+hmac_md5(const uint8_t *text, size_t text_len,
+ const uint8_t *key, size_t key_len,
uint8_t *digest)
{
uint8_t k_ipad[HMAC_PAD_LEN], k_opad[HMAC_PAD_LEN];
#include "platform.h"
struct dhcp_opt *
-vivso_find(uint16_t iana_en, const void *arg)
+vivso_find(uint32_t iana_en, const void *arg)
{
const struct interface *ifp;
size_t i;
}
size_t
-dhcp_vendor(char *str, size_t str_len)
+dhcp_vendor(char *str, size_t len)
{
struct utsname utn;
char *p;
+ int l;
if (uname(&utn) != 0)
- return snprintf(str, str_len, "%s-%s", PACKAGE, VERSION);
+ return (size_t)snprintf(str, len, "%s-%s",
+ PACKAGE, VERSION);
p = str;
- p += snprintf(str, str_len,
+ l = snprintf(p, len,
"%s-%s:%s-%s:%s", PACKAGE, VERSION,
utn.sysname, utn.release, utn.machine);
- p += hardware_platform(p, str_len - (p - str));
- return p - str;
+ p += l;
+ len -= (size_t)l;
+ l = hardware_platform(p, len);
+ return (size_t)(p - str);
}
int
match = 1;
else {
errno = 0;
- n = strtol(token, &t, 0);
+ n = (unsigned int)strtol(token, &t, 0);
if (errno == 0 && !*t)
if (opt->option == n)
match = 1;
break;
has_dot = 1;
if (dst) {
- *lp = p - lp - 1;
+ *lp = (uint8_t)(p - lp - 1);
if (*lp == '\0')
return len;
lp = p++;
}
if (dst) {
- *lp = p - lp - 1;
+ *lp = (uint8_t)(p - lp - 1);
if (has_dot)
*p++ = '\0';
}
* terminating zero) or zero on error. out may be NULL
* to just determine output length. */
ssize_t
-decode_rfc3397(char *out, ssize_t len, int pl, const uint8_t *p)
+decode_rfc3397(char *out, size_t len, const uint8_t *p, size_t pl)
{
const char *start;
- ssize_t start_len;
- const uint8_t *r, *q = p;
- int count = 0, l, hops;
+ size_t start_len, l;
+ const uint8_t *r, *q = p, *e;
+ int count = 0, hops;
uint8_t ltype;
start = out;
start_len = len;
- while (q - p < pl) {
+ q = p;
+ e = p + pl;
+ while (q < e) {
r = NULL;
hops = 0;
/* Check we are inside our length again in-case
* the name isn't fully qualified (ie, not terminated) */
- while (q - p < pl && (l = *q++)) {
+ while (q < e && (l = (size_t)*q++)) {
ltype = l & 0xc0;
if (ltype == 0x80 || ltype == 0x40)
- return 0;
+ return -1;
else if (ltype == 0xc0) { /* pointer */
l = (l & 0x3f) << 8;
l |= *q++;
if (!r)
r = q;
hops++;
- if (hops > 255)
- return 0;
+ if (hops > 255) {
+ errno = ERANGE;
+ return -1;
+ }
q = p + l;
- if (q - p >= pl)
- return 0;
+ if (q >= e) {
+ errno = ERANGE;
+ return -1;
+ }
} else {
/* straightforward name segment, add with '.' */
count += l + 1;
if (out) {
- if ((ssize_t)l + 1 > len) {
+ if (l + 1 > len) {
errno = ENOBUFS;
return -1;
}
}
ssize_t
-print_string(char *s, ssize_t len, int dl, const uint8_t *data)
+print_string(char *s, size_t len, const uint8_t *data, size_t dl)
{
uint8_t c;
const uint8_t *e, *p;
return -1;
}
r = snprintf(s, len, "\\%03o", c);
- len -= r;
+ len -= (size_t)r;
bytes += r;
s += r;
} else
break;
}
if (s) {
- *s++ = c;
+ *s++ = (char)c;
len--;
}
bytes++;
if (opt->len) {
if ((size_t)opt->len > dl)
return 0;
- return opt->len;
+ return (size_t)opt->len;
}
return dl;
}
#endif
ssize_t
-print_option(char *s, ssize_t len, int type, int dl, const uint8_t *data,
+print_option(char *s, size_t len, int type, const uint8_t *data, size_t dl,
PO_IFNAME const char *ifname)
{
const uint8_t *e, *t;
uint32_t u32;
int32_t s32;
struct in_addr addr;
- ssize_t bytes = 0;
- ssize_t l;
+ ssize_t bytes = 0, sl;
+ size_t l;
char *tmp;
if (type & RFC3397) {
- l = decode_rfc3397(NULL, 0, dl, data);
- if (l < 1)
- return l;
+ sl = decode_rfc3397(NULL, 0, data, dl);
+ if (sl == 0 || sl == -1)
+ return sl;
+ l = (size_t)sl;
tmp = malloc(l);
if (tmp == NULL)
return -1;
- decode_rfc3397(tmp, l, dl, data);
- l = print_string(s, len, l - 1, (uint8_t *)tmp);
+ decode_rfc3397(tmp, l, data, dl);
+ sl = print_string(s, len, (uint8_t *)tmp, l - 1);
free(tmp);
- return l;
+ return sl;
}
#ifdef INET
if (type & RFC3361) {
- if ((tmp = decode_rfc3361(dl, data)) == NULL)
+ if ((tmp = decode_rfc3361(data, dl)) == NULL)
return -1;
l = strlen(tmp);
- l = print_string(s, len, l, (uint8_t *)tmp);
+ sl = print_string(s, len, (uint8_t *)tmp, l);
free(tmp);
- return l;
+ return sl;
}
if (type & RFC3442)
- return decode_rfc3442(s, len, dl, data);
+ return decode_rfc3442(s, len, data, dl);
if (type & RFC5969)
- return decode_rfc5969(s, len, dl, data);
+ return decode_rfc5969(s, len, data, dl);
#endif
if (type & STRING) {
/* Some DHCP servers return NULL strings */
if (*data == '\0')
return 0;
- return print_string(s, len, dl, data);
+ return print_string(s, len, data, dl);
}
if (type & FLAG) {
while (data < e) {
if (l)
l++; /* space */
- dl = ipv6_printaddr(NULL, 0, data, ifname);
- if (dl != -1)
- l += dl;
+ sl = ipv6_printaddr(NULL, 0, data, ifname);
+ if (sl != -1)
+ l += (size_t)sl;
data += 16;
}
- return l + 1;
+ return (ssize_t)(l + 1);
}
#endif
else if (type & BINHEX) {
errno = EINVAL;
return -1;
}
- return (l + 1) * dl;
+ return (ssize_t)((l + 1) * dl);
}
t = data;
len--;
}
if (type & UINT8) {
- l = snprintf(s, len, "%u", *data);
+ sl = snprintf(s, len, "%u", *data);
data++;
} else if (type & UINT16) {
memcpy(&u16, data, sizeof(u16));
u16 = ntohs(u16);
- l = snprintf(s, len, "%u", u16);
+ sl = snprintf(s, len, "%u", u16);
data += sizeof(u16);
} else if (type & SINT16) {
- memcpy(&s16, data, sizeof(s16));
- s16 = ntohs(s16);
- l = snprintf(s, len, "%d", s16);
- data += sizeof(s16);
+ memcpy(&u16, data, sizeof(u16));
+ s16 = (int16_t)ntohs(u16);
+ sl = snprintf(s, len, "%d", s16);
+ data += sizeof(u16);
} else if (type & UINT32) {
memcpy(&u32, data, sizeof(u32));
u32 = ntohl(u32);
- l = snprintf(s, len, "%u", u32);
+ sl = snprintf(s, len, "%u", u32);
data += sizeof(u32);
} else if (type & SINT32) {
- memcpy(&s32, data, sizeof(s32));
- s32 = ntohl(s32);
- l = snprintf(s, len, "%d", s32);
- data += sizeof(s32);
+ memcpy(&u32, data, sizeof(u32));
+ s32 = (int32_t)ntohl(u32);
+ sl = snprintf(s, len, "%d", s32);
+ data += sizeof(u32);
} else if (type & ADDRIPV4) {
memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
- l = snprintf(s, len, "%s", inet_ntoa(addr));
+ sl = snprintf(s, len, "%s", inet_ntoa(addr));
data += sizeof(addr.s_addr);
}
#ifdef INET6
else if (type & ADDRIPV6) {
- dl = ipv6_printaddr(s, len, data, ifname);
- if (dl != -1)
- l = dl;
+ ssize_t r;
+
+ r = ipv6_printaddr(s, len, data, ifname);
+ if (r != -1)
+ sl = r;
else
- l = 0;
+ sl = 0;
data += 16;
}
#endif
else if (type & BINHEX) {
- l = snprintf(s, len, "%.2x", data[0]);
+ sl = snprintf(s, len, "%.2x", data[0]);
data++;
} else
- l = 0;
- len -= l;
- bytes += l;
- s += l;
+ sl = 0;
+ len -= (size_t)sl;
+ bytes += sl;
+ s += sl;
}
return bytes;
static size_t
dhcp_envoption1(char **env, const char *prefix,
- const struct dhcp_opt *opt, int vname, const uint8_t *od, int ol,
+ const struct dhcp_opt *opt, int vname, const uint8_t *od, size_t ol,
const char *ifname)
{
ssize_t len;
if (opt->len && opt->len < ol)
ol = opt->len;
- len = print_option(NULL, 0, opt->type, ol, od, ifname);
+ len = print_option(NULL, 0, opt->type, od, ol, ifname);
if (len < 0)
return 0;
if (vname)
e = 0;
if (prefix)
e += strlen(prefix);
- e += len + 4;
+ e += (size_t)len + 4;
if (env == NULL)
return e;
v = val = *env = malloc(e);
else
v += snprintf(val, e, "%s=", prefix);
if (len != 0)
- print_option(v, len, opt->type, ol, od, ifname);
+ print_option(v, (size_t)len, opt->type, od, ol, ifname);
return e;
}
-ssize_t
+size_t
dhcp_envoption(struct dhcpcd_ctx *ctx, char **env, const char *prefix,
const char *ifname, struct dhcp_opt *opt,
const uint8_t *(*dgetopt)(struct dhcpcd_ctx *,
unsigned int *, unsigned int *, unsigned int *,
const uint8_t *, unsigned int, struct dhcp_opt **),
- const uint8_t *od, int ol)
+ const uint8_t *od, size_t ol)
{
- ssize_t e, n;
- size_t i;
+ size_t e, i, n;
unsigned int eoc, eos, eol;
const uint8_t *eod;
int ov;
struct dhcp_opt {
uint32_t option; /* Also used for IANA Enterpise Number */
int type;
- int len;
+ size_t len;
char *var;
int index; /* Index counter for many instances of the same option */
size_t encopts_len;
};
-struct dhcp_opt *vivso_find(uint16_t, const void *);
+struct dhcp_opt *vivso_find(uint32_t, const void *);
size_t dhcp_vendor(char *, size_t);
uint8_t *, const char *, int);
size_t encode_rfc1035(const char *src, uint8_t *dst);
-ssize_t decode_rfc3397(char *, ssize_t, int, const uint8_t *);
-ssize_t print_string(char *, ssize_t, int, const uint8_t *);
-ssize_t print_option(char *, ssize_t, int, int, const uint8_t *, const char *);
+ssize_t decode_rfc3397(char *, size_t, const uint8_t *, size_t);
+ssize_t print_string(char *, size_t, const uint8_t *, size_t);
+ssize_t print_option(char *, size_t, int, const uint8_t *, size_t,
+ const char *);
-ssize_t dhcp_envoption(struct dhcpcd_ctx *,
+size_t dhcp_envoption(struct dhcpcd_ctx *,
char **, const char *, const char *, struct dhcp_opt *,
const uint8_t *(*dgetopt)(struct dhcpcd_ctx *,
- unsigned int *, unsigned int *, unsigned int *,
- const uint8_t *, unsigned int, struct dhcp_opt **),
- const uint8_t *od, int ol);
+ size_t *, unsigned int *, size_t *,
+ const uint8_t *, size_t, struct dhcp_opt **),
+ const uint8_t *od, size_t ol);
void dhcp_zero_index(struct dhcp_opt *);
#endif
#define get_option_raw(ctx, dhcp, opt) get_option(ctx, dhcp, opt, NULL)
static const uint8_t *
get_option(struct dhcpcd_ctx *ctx,
- const struct dhcp_message *dhcp, uint8_t opt, int *len)
+ const struct dhcp_message *dhcp, unsigned int opt, size_t *len)
{
const uint8_t *p = dhcp->options;
const uint8_t *e = p + sizeof(dhcp->options);
uint8_t overl = 0;
uint8_t *bp = NULL;
const uint8_t *op = NULL;
- int bl = 0;
+ size_t bl = 0;
while (p < e) {
o = *p++;
uint8_t option)
{
const uint8_t *p;
- int len;
+ size_t len;
p = get_option(ctx, dhcp, option, &len);
if (!p || len < (ssize_t)sizeof(a->s_addr))
uint32_t *i, const struct dhcp_message *dhcp, uint8_t option)
{
const uint8_t *p;
- int len;
+ size_t len;
uint32_t d;
p = get_option(ctx, dhcp, option, &len);
uint8_t *i, const struct dhcp_message *dhcp, uint8_t option)
{
const uint8_t *p;
- int len;
+ size_t len;
p = get_option(ctx, dhcp, option, &len);
if (!p || len < (ssize_t)sizeof(*p))
}
ssize_t
-decode_rfc3442(char *out, ssize_t len, int pl, const uint8_t *p)
+decode_rfc3442(char *out, size_t len, const uint8_t *p, size_t pl)
{
const uint8_t *e;
- ssize_t b, bytes = 0, ocets;
+ size_t bytes = 0, ocets;
+ int b;
uint8_t cidr;
struct in_addr addr;
char *o = out;
} else
b = snprintf(o, len, "0.0.0.0/0");
o += b;
- len -= b;
+ len -= (size_t)b;
/* Finally, snag the router */
memcpy(&addr.s_addr, p, 4);
p += 4;
b = snprintf(o, len, " %s", inet_ntoa(addr));
o += b;
- len -= b;
+ len -= (size_t)b;
}
if (out)
return o - out;
- return bytes;
+ return (ssize_t)bytes;
}
static struct rt_head *
-decode_rfc3442_rt(int dl, const uint8_t *data)
+decode_rfc3442_rt(const uint8_t *data, size_t dl)
{
const uint8_t *p = data;
const uint8_t *e;
}
char *
-decode_rfc3361(int dl, const uint8_t *data)
+decode_rfc3361(const uint8_t *data, size_t dl)
{
uint8_t enc;
- unsigned int l;
+ size_t l;
+ ssize_t r;
char *sip = NULL;
struct in_addr addr;
char *p;
dl--;
switch (enc) {
case 0:
- if ((l = decode_rfc3397(NULL, 0, dl, data)) > 0) {
+ if ((r = decode_rfc3397(NULL, 0, data, dl)) > 0) {
+ l = (size_t)r;
sip = malloc(l);
if (sip == NULL)
return 0;
- decode_rfc3397(sip, l, dl, data);
+ decode_rfc3397(sip, l, data, dl);
}
break;
case 1:
while (dl != 0) {
memcpy(&addr.s_addr, data, sizeof(addr.s_addr));
data += sizeof(addr.s_addr);
- p += snprintf(p, l - (p - sip), "%s ", inet_ntoa(addr));
+ p += snprintf(p, l - (size_t)(p - sip),
+ "%s ", inet_ntoa(addr));
dl -= sizeof(addr.s_addr);
}
*--p = '\0';
* separated string. Returns length of string (including
* terminating zero) or zero on error. */
ssize_t
-decode_rfc5969(char *out, ssize_t len, int pl, const uint8_t *p)
+decode_rfc5969(char *out, size_t len, const uint8_t *p, size_t pl)
{
uint8_t ipv4masklen, ipv6prefixlen;
uint8_t ipv6prefix[16];
ipv6prefix[12],ipv6prefix[13],ipv6prefix[14], ipv6prefix[15]
);
- len -= b;
+ len -= (size_t)b;
out += b;
bytes += b;
} else {
if (out) {
b= snprintf(out, len, " %d.%d.%d.%d",
br[0], br[1], br[2], br[3]);
- len -= b;
+ len -= (size_t)b;
out += b;
bytes += b;
} else {
get_option_string(struct dhcpcd_ctx *ctx,
const struct dhcp_message *dhcp, uint8_t option)
{
- int len;
+ size_t len;
const uint8_t *p;
char *s;
const uint8_t *e;
struct rt_head *routes = NULL;
struct rt *route = NULL;
- int len;
+ size_t len;
const char *csr = "";
/* If we have CSR's then we MUST use these only */
csr = "MS ";
}
if (p) {
- routes = decode_rfc3442_rt(len, p);
+ routes = decode_rfc3442_rt(p, len);
if (routes) {
if (!(ifo->options & DHCPCD_CSR_WARNED)) {
syslog(LOG_DEBUG,
p += *p + 1;
}
- len = p - (uint8_t *)dhcp;
+ len = (size_t)(p - (uint8_t *)dhcp);
if (len + 6 > sizeof(*dhcp)) {
errno = ENOMEM;
return -1;
uint8_t *n_params = NULL;
uint32_t ul;
uint16_t sz;
- size_t len, i;
- int auth_len;
+ size_t len, i, auth_len;
const struct dhcp_opt *opt;
struct if_options *ifo = iface->options;
const struct dhcp_state *state = D_CSTATE(iface);
if (type == DHCP_DECLINE) {
*p++ = DHO_MESSAGE;
len = strlen(DAD);
- *p++ = len;
+ *p++ = (uint8_t)len;
memcpy(p, DAD, len);
p += len;
}
type == DHCP_INFORM ||
type == DHCP_REQUEST)
{
+ int mtu;
+
*p++ = DHO_MAXMESSAGESIZE;
*p++ = 2;
- sz = get_mtu(iface->name);
- if (sz < MTU_MIN) {
+ mtu = get_mtu(iface->name);
+ if (mtu < MTU_MIN) {
if (set_mtu(iface->name, MTU_MIN) == 0)
sz = MTU_MIN;
- } else if (sz > MTU_MAX) {
+ } else if (mtu > MTU_MAX) {
/* Even though our MTU could be greater than
* MTU_MAX (1500) dhcpcd does not presently
* handle DHCP packets any bigger. */
- sz = MTU_MAX;
+ mtu = MTU_MAX;
}
- sz = htons(sz);
+ sz = htons(mtu);
memcpy(p, &sz, 2);
p += 2;
} else if (ifo->options & DHCPCD_HOSTNAME && hostname) {
*p++ = DHO_HOSTNAME;
len = strlen(hostname);
- *p++ = len;
+ *p++ = (uint8_t)len;
memcpy(p, hostname, len);
p += len;
}
i < ifo->vivco_len;
i++, vivco++)
{
- len = (p - m) + vivco->len + 1;
+ len = (size_t)(p - m) + vivco->len + 1;
if (len > sizeof(*dhcp))
goto toobig;
if (vivco->len + 2 + *lp > 255) {
}
}
- len = (p - m) + 3;
+ len = (size_t)((p - m) + 3);
if (len > sizeof(*dhcp))
goto toobig;
*p++ = DHO_PARAMETERREQUESTLIST;
(opt->option == DHO_RENEWALTIME ||
opt->option == DHO_REBINDTIME))
continue;
- len = (p - m) + 2;
+ len = (size_t)((p - m) + 2);
if (len > sizeof(*dhcp))
goto toobig;
- *p++ = opt->option;
+ *p++ = (uint8_t)opt->option;
}
- *n_params = p - n_params - 1;
+ *n_params = (uint8_t)(p - n_params - 1);
}
/* silence GCC */
auth = NULL;
if (ifo->auth.options & DHCPCD_AUTH_SEND) {
- auth_len = dhcp_auth_encode(&ifo->auth, state->auth.token,
+ auth_len = (size_t)dhcp_auth_encode(&ifo->auth,
+ state->auth.token,
NULL, 0, 4, type, NULL, 0);
if (auth_len > 0) {
- len = (p + auth_len) - m;
+ len = (size_t)((p + auth_len) - m);
if (auth_len > 255 || len > sizeof(*dhcp))
goto toobig;
*p++ = DHO_AUTHENTICATION;
*p++ = (uint8_t)auth_len;
auth = p;
p += auth_len;
- } else if (auth_len == -1)
+ } else if ((ssize_t)auth_len == -1)
syslog(LOG_ERR, "%s: dhcp_auth_encode: %m",
iface->name);
}
*p++ = DHO_PAD;
#endif
- len = p - m;
+ len = (size_t)(p - m);
if (ifo->auth.options & DHCPCD_AUTH_SEND && auth_len > 0)
dhcp_auth_encode(&ifo->auth, state->auth.token,
m, len, 4, type, auth, auth_len);
*message = dhcp;
- return len;
+ return (ssize_t)len;
toobig:
syslog(LOG_ERR, "%s: DHCP messge too big", iface->name);
write_lease(const struct interface *ifp, const struct dhcp_message *dhcp)
{
int fd;
+ size_t len;
ssize_t bytes;
const uint8_t *e, *p;
uint8_t l;
/* Only write as much as we need */
p = dhcp->options;
e = p + sizeof(dhcp->options);
- bytes = sizeof(*dhcp);
+ len = sizeof(*dhcp);
while (p < e) {
o = *p;
if (o == DHO_END) {
- bytes = p - (const uint8_t *)dhcp;
+ len = (size_t)(p - (const uint8_t *)dhcp);
break;
}
p++;
p += l;
}
}
- bytes = write(fd, dhcp, bytes);
+ bytes = write(fd, dhcp, len);
close(fd);
return bytes;
}
ssize_t bytes;
const uint8_t *auth;
uint8_t type;
- int auth_len;
+ size_t auth_len;
fd = open(state->leasefile, O_RDONLY);
if (fd == -1) {
}
static const struct dhcp_opt *
-dhcp_getoverride(const struct if_options *ifo, uint16_t o)
+dhcp_getoverride(const struct if_options *ifo, unsigned int o)
{
size_t i;
const struct dhcp_opt *opt;
static const uint8_t *
dhcp_getoption(struct dhcpcd_ctx *ctx,
- unsigned int *os, unsigned int *code, unsigned int *len,
- const uint8_t *od, unsigned int ol, struct dhcp_opt **oopt)
+ size_t *os, unsigned int *code, size_t *len,
+ const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
{
size_t i;
struct dhcp_opt *opt;
return NULL;
}
*os = 2; /* code + len */
- *code = (int)*od++;
- *len = (int)*od++;
+ *code = (unsigned int)*od++;
+ *len = (size_t)*od++;
if (*len > ol) {
errno = EINVAL;
return NULL;
{
const struct if_options *ifo;
const uint8_t *p;
- int pl;
struct in_addr addr;
struct in_addr net;
struct in_addr brd;
struct dhcp_opt *opt, *vo;
- ssize_t e = 0;
+ size_t e, i, pl;
char **ep;
char cidr[4];
uint8_t overl = 0;
- size_t i;
uint32_t en;
+ e = 0;
ifo = ifp->options;
get_option_uint8(ifp->ctx, &overl, dhcp, DHO_OPTIONSOVERLOADED);
e += dhcp_envoption(ifp->ctx, NULL, NULL, ifp->name,
opt, dhcp_getoption, p, pl);
}
- return e;
+ return (ssize_t)e;
}
ep = env;
static ssize_t
dhcp_sendpacket(const struct interface *iface, struct in_addr to,
- const uint8_t *data, ssize_t len)
+ const uint8_t *data, size_t len)
{
struct sockaddr_in sin;
{
const uint8_t *addr = data;
uint32_t sum = 0;
+ uint16_t res;
while (len > 1) {
sum += addr[0] * 256 + addr[1];
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
- sum = htons(sum);
+ res = htons(sum);
- return ~sum;
+ return ~res;
}
static struct udp_dhcp_packet *
-dhcp_makeudppacket(ssize_t *sz, const uint8_t *data, size_t length,
+dhcp_makeudppacket(size_t *sz, const uint8_t *data, size_t length,
struct in_addr source, struct in_addr dest)
{
struct udp_dhcp_packet *udpp;
}
static void
-send_message(struct interface *iface, int type,
+send_message(struct interface *iface, uint8_t type,
void (*callback)(void *))
{
struct dhcp_state *state = D_STATE(iface);
struct if_options *ifo = iface->options;
struct dhcp_message *dhcp;
struct udp_dhcp_packet *udp;
- ssize_t len, r;
+ size_t len;
+ ssize_t r;
struct in_addr from, to;
in_addr_t a = 0;
struct timeval tv;
a = state->addr.s_addr;
state->addr.s_addr = 0;
}
- len = make_message(&dhcp, iface, type);
+ r = make_message(&dhcp, iface, type);
+ if (r == -1)
+ goto fail;
+ len = (size_t)r;
if (a)
state->addr.s_addr = a;
from.s_addr = dhcp->ciaddr;
dhcp_close(iface);
}
} else {
+ size_t ulen;
+
r = 0;
- udp = dhcp_makeudppacket(&r, (uint8_t *)dhcp, len, from, to);
+ udp = dhcp_makeudppacket(&ulen, (uint8_t *)dhcp, len, from, to);
if (udp == NULL) {
syslog(LOG_ERR, "dhcp_makeudppacket: %m");
} else {
r = ipv4_sendrawpacket(iface, ETHERTYPE_IP,
- (uint8_t *)udp, r);
+ (uint8_t *)udp, ulen);
free(udp);
}
/* If we failed to send a raw packet this normally means
}
free(dhcp);
+fail:
/* Even if we fail to send a packet we should continue as we are
* as our failure timeouts will change out codepath when needed. */
if (callback)
struct interface *iface = arg;
struct dhcp_state *state = D_STATE(iface);
struct if_options *ifo = iface->options;
- int timeout = ifo->timeout;
+ time_t timeout = ifo->timeout;
/* If we're rebooting and we're not daemonised then we need
* to shorten the normal timeout to ensure we try correctly
if (state->state == DHS_REBOOT &&
!(iface->ctx->options & DHCPCD_DAEMONISED))
{
- timeout -= ifo->reboot;
- if (timeout <= 0)
+ if (ifo->reboot >= timeout)
timeout = 2;
+ else
+ timeout -= ifo->reboot;
}
state->state = DHS_DISCOVER;
lease->leasetime = DHCP_MIN_LEASE;
}
if (lease->rebindtime == 0)
- lease->rebindtime = lease->leasetime * T2;
+ lease->rebindtime =
+ (uint32_t)(lease->leasetime * T2);
else if (lease->rebindtime >= lease->leasetime) {
- lease->rebindtime = lease->leasetime * T2;
+ lease->rebindtime =
+ (uint32_t)(lease->leasetime * T2);
syslog(LOG_WARNING,
"%s: rebind time greater than lease "
"time, forcing to %"PRIu32" seconds",
iface->name, lease->rebindtime);
}
if (lease->renewaltime == 0)
- lease->renewaltime = lease->leasetime * T1;
+ lease->renewaltime =
+ (uint32_t)(lease->leasetime * T1);
else if (lease->renewaltime > lease->rebindtime) {
- lease->renewaltime = lease->leasetime * T1;
+ lease->renewaltime =
+ (uint32_t)(lease->leasetime * T1);
syslog(LOG_WARNING,
"%s: renewal time greater than rebind "
"time, forcing to %"PRIu32" seconds",
}
void
-dhcp_reboot_newopts(struct interface *ifp, int oldopts)
+dhcp_reboot_newopts(struct interface *ifp, unsigned long long oldopts)
{
struct if_options *ifo;
struct dhcp_state *state = D_STATE(ifp);
uint8_t type, tmp;
const uint8_t *auth;
struct in_addr addr;
- size_t i;
- int auth_len;
+ unsigned int i;
+ size_t auth_len;
char *msg;
/* We may have found a BOOTP server */
case 1:
log_dhcp(LOG_WARNING, "IPv4LL enabled from",
iface, dhcp, from);
- eloop_timeout_delete(iface->ctx->eloop, NULL, iface);
+ eloop_timeout_delete(iface->ctx->eloop,
+ NULL, iface);
if (IN_LINKLOCAL(htonl(state->addr.s_addr)))
eloop_timeout_add_sec(iface->ctx->eloop,
DHCP_MAX, dhcp_discover, iface);
/* Ensure that all required options are present */
for (i = 1; i < 255; i++) {
if (has_option_mask(ifo->requiremask, i) &&
- get_option_uint8(iface->ctx, &tmp, dhcp, i) != 0)
+ get_option_uint8(iface->ctx, &tmp, dhcp, (uint8_t)i) != 0)
{
/* If we are bootp, then ignore the need for serverid.
* To ignore bootp, require dhcp_message_type. */
dhcp_bind(iface);
}
-static ssize_t
+static size_t
get_udp_data(const uint8_t **data, const uint8_t *udp)
{
struct udp_dhcp_packet p;
struct interface *iface = arg;
struct dhcp_message *dhcp = NULL;
const uint8_t *pp;
- ssize_t bytes;
+ size_t bytes;
struct in_addr from;
int i, partialcsum = 0;
const struct dhcp_state *state = D_CSTATE(iface);
* The benefit is that if we get >1 DHCP packet in our buffer and
* the first one fails for any reason, we can use the next. */
for(;;) {
- bytes = ipv4_getrawpacket(iface, ETHERTYPE_IP,
+ bytes = (size_t)ipv4_getrawpacket(iface, ETHERTYPE_IP,
iface->ctx->packet, udp_dhcp_len, &partialcsum);
- if (bytes == 0 || bytes == -1)
+ if (bytes == 0 || (ssize_t)bytes == -1)
break;
if (valid_udp_packet(iface->ctx->packet, bytes,
&from, partialcsum) == -1)
iface->name, inet_ntoa(from));
}
bytes = get_udp_data(&pp, iface->ctx->packet);
- if ((size_t)bytes > sizeof(*dhcp)) {
+ if (bytes > sizeof(*dhcp)) {
syslog(LOG_ERR,
"%s: packet greater than DHCP size from %s",
iface->name, inet_ntoa(from));
{
struct dhcp_state *state;
const struct if_options *ifo;
- size_t len;
+ uint8_t len;
char buf[(sizeof(ifo->clientid) - 1) * 3];
state = D_STATE(ifp);
state->clientid = NULL;
if (*ifo->clientid) {
- state->clientid = malloc(ifo->clientid[0] + 1);
+ state->clientid = malloc((size_t)(ifo->clientid[0] + 1));
if (state->clientid == NULL)
goto eexit;
- memcpy(state->clientid, ifo->clientid, ifo->clientid[0] + 1);
+ memcpy(state->clientid, ifo->clientid,
+ (size_t)(ifo->clientid[0]) + 1);
} else if (ifo->options & DHCPCD_CLIENTID) {
if (ifo->options & DHCPCD_DUID) {
state->clientid = malloc(ifp->ctx->duid_len + 6);
if (state->clientid == NULL)
goto eexit;
- state->clientid[0] = ifp->ctx->duid_len + 5;
+ state->clientid[0] =(uint8_t)(ifp->ctx->duid_len + 5);
state->clientid[1] = 255; /* RFC 4361 */
memcpy(state->clientid + 2, ifo->iaid, 4);
memcpy(state->clientid + 6, ifp->ctx->duid,
ifp->ctx->duid_len);
} else {
- len = ifp->hwlen + 1;
- state->clientid = malloc(len + 1);
+ len = (uint8_t)(ifp->hwlen + 1);
+ state->clientid = malloc((size_t)len + 1);
if (state->clientid == NULL)
goto eexit;
state->clientid[0] = len;
- state->clientid[1] = ifp->family;
+ state->clientid[1] = (uint8_t)ifp->family;
memcpy(state->clientid + 2, ifp->hwaddr,
ifp->hwlen);
}
state->offer = NULL;
state->lease.addr.s_addr = 0;
} else {
- l = now.tv_sec - st.st_mtime;
+ l = (uint32_t)(now.tv_sec - st.st_mtime);
state->lease.leasetime -= l;
state->lease.renewaltime -= l;
state->lease.rebindtime -= l;
{
struct dhcp_state *state;
struct if_options *ifo;
- int i;
+ uint8_t i;
state = D_STATE(ifp);
if (state == NULL)
#include "net.h"
#ifdef INET
-char *decode_rfc3361(int dl, const uint8_t *data);
-ssize_t decode_rfc3442(char *out, ssize_t len, int pl, const uint8_t *p);
-ssize_t decode_rfc5969(char *out, ssize_t len, int pl, const uint8_t *p);
+char *decode_rfc3361(const uint8_t *, size_t);
+ssize_t decode_rfc3442(char *, size_t, const uint8_t *p, size_t);
+ssize_t decode_rfc5969(char *, size_t, const uint8_t *p, size_t);
void dhcp_printoptions(const struct dhcpcd_ctx *);
int get_option_addr(struct dhcpcd_ctx *,struct in_addr *,
void dhcp_discover(void *);
void dhcp_inform(struct interface *);
void dhcp_bind(void *);
-void dhcp_reboot_newopts(struct interface *, int);
+void dhcp_reboot_newopts(struct interface *, unsigned long long);
void dhcp_close(struct interface *);
void dhcp_free(struct interface *);
int dhcp_dump(struct dhcpcd_ctx *, const char *);
}
static const struct dhcp6_option *
-dhcp6_findoption(int code, const uint8_t *d, ssize_t len)
+dhcp6_findoption(unsigned int code, const uint8_t *d, size_t len)
{
const struct dhcp6_option *o;
+ size_t ol;
code = htons(code);
for (o = (const struct dhcp6_option *)d;
len > (ssize_t)sizeof(*o);
o = D6_CNEXT_OPTION(o))
{
- len -= sizeof(*o) + ntohs(o->len);
- if (len < 0) {
+ ol = sizeof(*o) + ntohs(o->len);
+ if (ol > len) {
errno = EINVAL;
return NULL;
}
if (o->code == code)
return o;
+ len -= ol;
}
errno = ESRCH;
static const uint8_t *
dhcp6_getoption(struct dhcpcd_ctx *ctx,
- unsigned int *os, unsigned int *code, unsigned int *len,
- const uint8_t *od, unsigned int ol, struct dhcp_opt **oopt)
+ size_t *os, unsigned int *code, size_t *len,
+ const uint8_t *od, size_t ol, struct dhcp_opt **oopt)
{
const struct dhcp6_option *o;
size_t i;
}
static const struct dhcp6_option *
-dhcp6_getmoption(int code, const struct dhcp6_message *m, ssize_t len)
+dhcp6_getmoption(unsigned int code, const struct dhcp6_message *m, size_t len)
{
len -= sizeof(*m);
}
static int
-dhcp6_updateelapsed(struct interface *ifp, struct dhcp6_message *m, ssize_t len)
+dhcp6_updateelapsed(struct interface *ifp, struct dhcp6_message *m, size_t len)
{
struct dhcp6_state *state;
const struct dhcp6_option *co;
struct dhcp6_message *m;
struct dhcp6_option *o, *so;
const struct dhcp6_option *si, *unicast;
- ssize_t len, ml;
- size_t l;
- int auth_len;
- uint8_t u8;
- uint16_t *u16, n_options, type;
+ size_t l, len, ml, auth_len;
+ uint8_t u8, type;
+ uint16_t *u16, n_options;
struct if_options *ifo;
const struct dhcp_opt *opt;
uint8_t IA, *p;
}
if (ifo->auth.options & DHCPCD_AUTH_SEND) {
- auth_len = dhcp_auth_encode(&ifo->auth, state->auth.token,
- NULL, 0, 6, type, NULL, 0);
- if (auth_len > 0)
+ auth_len = (size_t)dhcp_auth_encode(&ifo->auth,
+ state->auth.token, NULL, 0, 6, type, NULL, 0);
+ if ((ssize_t)auth_len == -1)
+ auth_len = 0;
+ else if (auth_len> 0)
len += sizeof(*o) + auth_len;
} else
auth_len = 0; /* appease GCC */
static int
-dhcp6_update_auth(struct interface *ifp, struct dhcp6_message *m, ssize_t len)
+dhcp6_update_auth(struct interface *ifp, struct dhcp6_message *m, size_t len)
{
struct dhcp6_state *state;
const struct dhcp6_option *co;
struct in6_pktinfo pi;
struct timeval RTprev;
double rnd;
- suseconds_t ms;
+ time_t ms;
uint8_t neg;
const char *broad_uni;
const struct in6_addr alldhcp = IN6ADDR_LINKLOCAL_ALLDHCP_INIT;
state->RT.tv_sec = 1;
else
state->RT.tv_sec = 0;
- state->RT.tv_usec = arc4random() %
- (state->IMD * 1000000);
+ state->RT.tv_usec = (suseconds_t)(arc4random() %
+ (state->IMD * 1000000));
timernorm(&state->RT);
broad_uni = "delaying";
goto logsend;
const char *ia;
int i;
uint32_t u32;
+ size_t off;
i = 0;
state = D6_STATE(ifp);
while ((o = dhcp6_findoption(D6_OPTION_IA_ADDR, d, l))) {
- l -= ((const uint8_t *)o - d);
- d += ((const uint8_t *)o - d);
+ off = (size_t)((const uint8_t *)o - d);
+ l -= off;
+ d += off;
u32 = ntohs(o->len);
l -= sizeof(*o) + u32;
d += sizeof(*o) + u32;
uint8_t u8, len;
uint32_t u32, pltime, vltime;
struct in6_addr prefix;
+ size_t off;
i = 0;
state = D6_STATE(ifp);
while ((o = dhcp6_findoption(D6_OPTION_IAPREFIX, d, l))) {
- l -= ((const uint8_t *)o - d);
- d += ((const uint8_t *)o - d);
+ off = (size_t)((const uint8_t *)o - d);
+ l -= off;
+ d += off;
u32 = ntohs(o->len);
l -= sizeof(*o) + u32;
d += sizeof(*o) + u32;
ap->flags |= IPV6_AF_STALE;
}
while ((o = dhcp6_findoption(ifo->ia_type, d, l))) {
- l -= ((const uint8_t *)o - d);
- d += ((const uint8_t *)o - d);
+ ol = (size_t)((const uint8_t *)o - d);
+ l -= ol;
+ d += ol;
ol = ntohs(o->len);
l -= sizeof(*o) + ol;
d += sizeof(*o) + ol;
state->renew = state->rebind = state->expire = 0;
state->lowpl = ND6_INFINITE_LIFETIME;
- len -= (const char *)o - (const char *)m;
+ len -= (size_t)((const char *)o - (const char *)m);
return dhcp6_findia(ifp, (const uint8_t *)o, len, sfrom);
}
}
syslog(LOG_DEBUG, "%s: reading lease `%s'",
ifp->name, state->leasefile);
- state->new = malloc(st.st_size);
+ if (st.st_size > SIZE_MAX) {
+ syslog(LOG_ERR, "%s: file too big", ifp->name);
+ return -1;
+ }
+ state->new = malloc((size_t)st.st_size);
if (state->new == NULL)
return -1;
- state->new_len = st.st_size;
+ state->new_len = (size_t)st.st_size;
fd = open(state->leasefile, O_RDONLY);
if (fd == -1)
return -1;
if (sla == NULL) {
struct interface *ifi;
unsigned int idx;
+ int bits;
asla.sla = ifp->index;
/* Work out our largest index delegating to. */
if (ifi != ifp && ifi->index > idx)
idx = ifi->index;
}
- asla.prefix_len = prefix->prefix_len + ffs((int)idx);
+ bits = ffs((int)idx);
+ if (prefix->prefix_len + bits > UINT8_MAX)
+ asla.prefix_len = UINT8_MAX;
+ else {
+ asla.prefix_len = prefix->prefix_len + (uint8_t)bits;
- /* Make a 64 prefix by default, as this maks SLAAC
- * possible. Otherwise round up to the nearest octet. */
- if (asla.prefix_len <= 64)
- asla.prefix_len = 64;
- else
- asla.prefix_len = ROUNDUP8(asla.prefix_len);
+ /* Make a 64 prefix by default, as this maks SLAAC
+ * possible. Otherwise round up to the nearest octet. */
+ if (asla.prefix_len <= 64)
+ asla.prefix_len = 64;
+ else
+ asla.prefix_len = ROUNDUP8(asla.prefix_len);
+ }
sla = &asla;
}
dhcp6_find_delegates(arg);
}
-int
+size_t
dhcp6_find_delegates(struct interface *ifp)
{
struct if_options *ifo;
{
struct dhcpcd_ctx *dhcpcd_ctx;
struct ipv6_ctx *ctx;
- ssize_t len;
- size_t i;
+ size_t i, len;
+ ssize_t bytes;
struct cmsghdr *cm;
struct in6_pktinfo pkt;
struct interface *ifp;
dhcpcd_ctx = arg;
ctx = dhcpcd_ctx->ipv6;
ctx->rcvhdr.msg_controllen = CMSG_SPACE(sizeof(struct in6_pktinfo));
- len = recvmsg(ctx->dhcp_fd, &ctx->rcvhdr, 0);
- if (len == -1) {
+ bytes = recvmsg(ctx->dhcp_fd, &ctx->rcvhdr, 0);
+ if (bytes == -1) {
syslog(LOG_ERR, "recvmsg: %m");
return;
}
+ len = (size_t)bytes;
ctx->sfrom = inet_ntop(AF_INET6, &ctx->from.sin6_addr,
ctx->ntopbuf, sizeof(ctx->ntopbuf));
- if ((size_t)len < sizeof(struct dhcp6_message)) {
+ if (len < sizeof(struct dhcp6_message)) {
syslog(LOG_ERR, "DHCPv6 RA packet too short from %s",
ctx->sfrom);
return;
if (state->expire == ND6_INFINITE_LIFETIME)
state->renew = ND6_INFINITE_LIFETIME;
else
- state->renew = state->lowpl * 0.5;
+ state->renew = (uint32_t)(state->lowpl * 0.5);
}
if (state->rebind == 0) {
if (state->expire == ND6_INFINITE_LIFETIME)
state->rebind = ND6_INFINITE_LIFETIME;
else
- state->rebind = state->lowpl * 0.8;
+ state->rebind = (uint32_t)(state->lowpl * 0.8);
}
break;
default:
ssize_t
dhcp6_env(char **env, const char *prefix, const struct interface *ifp,
- const struct dhcp6_message *m, ssize_t len)
+ const struct dhcp6_message *m, size_t len)
{
const struct dhcp6_state *state;
const struct if_options *ifo;
pfx = malloc(i);
if (pfx == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
- return 0;
+ return -1;
}
snprintf(pfx, i, "%s_dhcp6", prefix);
} else
o = D6_CNEXT_OPTION(o))
{
ol = ntohs(o->len);
- len -= sizeof(*o) + ol;
- if (len < 0) {
- errno = EINVAL;
+ if (sizeof(*o) + ol > len) {
+ errno = EINVAL;
break;
}
+ len -= sizeof(*o) + ol;
oc = ntohs(o->code);
if (has_option_mask(ifo->nomask6, oc))
continue;
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- i = snprintf(v, l, "%s_dhcp6_prefix=",
+ i = (size_t)snprintf(v, l, "%s_dhcp6_prefix=",
prefix);
v += i;
l -= i;
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- i = snprintf(v, l, "%s_dhcp6_ip_address=",
+ i = (size_t)snprintf(v, l,
+ "%s_dhcp6_ip_address=",
prefix);
v += i;
l -= i;
n++;
}
- return n;
+ return (ssize_t)n;
}
/* Message retransmission timings */
struct timeval RT;
- int IMD;
- int RTC;
- int IRT;
- int MRC;
- int MRT;
+ unsigned int IMD;
+ unsigned int RTC;
+ unsigned int IRT;
+ unsigned int MRC;
+ unsigned int MRT;
void (*MRCcallback)(void *);
- int sol_max_rt;
- int inf_max_rt;
+ unsigned int sol_max_rt;
+ unsigned int inf_max_rt;
struct dhcp6_message *send;
size_t send_len;
#ifdef INET6
void dhcp6_printoptions(const struct dhcpcd_ctx *);
int dhcp6_addrexists(struct dhcpcd_ctx *, const struct ipv6_addr *);
-int dhcp6_find_delegates(struct interface *);
+size_t dhcp6_find_delegates(struct interface *);
int dhcp6_start(struct interface *, enum DH6S);
void dhcp6_reboot(struct interface *);
ssize_t dhcp6_env(char **, const char *, const struct interface *,
- const struct dhcp6_message *, ssize_t);
+ const struct dhcp6_message *, size_t);
void dhcp6_free(struct interface *);
void dhcp6_handleifa(struct dhcpcd_ctx *, int, const char *,
const struct in6_addr *addr, int);
ifo->options &= ~DHCPCD_LINK;
if (ifo->metric != -1)
- ifp->metric = ifo->metric;
+ ifp->metric = (unsigned int)ifo->metric;
if (!(ifo->options & DHCPCD_IPV6))
ifo->options &= ~DHCPCD_IPV6RS;
}
void
-handle_carrier(struct dhcpcd_ctx *ctx, int carrier, int flags,
+handle_carrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags,
const char *ifname)
{
struct interface *ifp;
{
struct interface *ifp = arg;
struct if_options *ifo = ifp->options;
- int nolease;
size_t i;
char buf[DUID_LEN * 3];
ipv6nd_startrs(ifp);
if (!(ifo->options & DHCPCD_IPV6RS)) {
+ ssize_t nolease;
+
if (ifo->options & DHCPCD_IA_FORCED)
nolease = dhcp6_start(ifp, DH6S_INIT);
else {
- nolease = dhcp6_find_delegates(ifp);
+ dhcp6_find_delegates(ifp);
+ nolease = 0;
/* Enabling the below doesn't really make
* sense as there is currently no standard
* to push routes via DHCPv6.
void
handle_hwaddr(struct dhcpcd_ctx *ctx, const char *ifname,
- const uint8_t *hwaddr, size_t hwlen)
+ const uint8_t *hwaddr, uint8_t hwlen)
{
struct interface *ifp;
char buf[sizeof(ifp->hwaddr) * 3];
static void
if_reboot(struct interface *ifp, int argc, char **argv)
{
- int oldopts;
+ unsigned long long oldopts;
oldopts = ifp->options->options;
script_runreason(ifp, "RECONFIGURE");
struct interface *ifp;
int do_exit = 0, do_release = 0, do_reboot = 0;
int opt, oi = 0;
- ssize_t len;
- size_t l;
+ size_t len, l;
struct iovec iov[2];
char *tmp, *p;
if (ipv6nd_has_ra(ifp))
len++;
}
- len = write(fd->fd, &len, sizeof(len));
- if (len != sizeof(len))
+ if (write(fd->fd, &len, sizeof(len) !=
+ sizeof(len)))
return -1;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
send_interface(fd->fd, ifp);
}
}
}
- len = write(fd->fd, &len, sizeof(len));
- if (len != sizeof(len))
+ if (write(fd->fd, &len, sizeof(len)) != sizeof(len))
return -1;
opt = 0;
while (argv[++opt] != NULL) {
struct interface *ifp;
uint16_t family = 0;
int opt, oi = 0, i;
- size_t len;
+ time_t t;
+ ssize_t len;
#if defined(USE_SIGNALS) || !defined(THERE_IS_NO_FORK)
pid_t pid;
#endif
}
}
if (ctx.options & DHCPCD_MASTER)
- i = ifo->timeout;
+ t = ifo->timeout;
else if ((ifp = TAILQ_FIRST(ctx.ifaces)))
- i = ifp->options->timeout;
+ t = ifp->options->timeout;
else
- i = 0;
+ t = 0;
if (opt == 0 &&
ctx.options & DHCPCD_LINK &&
!(ctx.options & DHCPCD_WAITIP))
syslog(LOG_WARNING, "no interfaces have a carrier");
if (daemonise(&ctx))
goto exit_success;
- } else if (i > 0) {
+ } else if (t > 0) {
if (ctx.options & DHCPCD_IPV4LL)
ctx.options |= DHCPCD_TIMEOUT_IPV4LL;
- eloop_timeout_add_sec(ctx.eloop, i,
+ eloop_timeout_add_sec(ctx.eloop, t,
handle_exit_timeout, &ctx);
}
}
TAILQ_ENTRY(interface) next;
char name[IF_NAMESIZE];
unsigned int index;
- int flags;
+ unsigned int flags;
sa_family_t family;
unsigned char hwaddr[HWADDR_LEN];
- size_t hwlen;
- int metric;
+ uint8_t hwlen;
+ unsigned int metric;
int carrier;
int wireless;
char ssid[IF_SSIDSIZE];
size_t dhcp6_opts_len;
struct ipv6_ctx *ipv6;
char **ra_restore;
- ssize_t ra_restore_len;
+ size_t ra_restore_len;
#ifndef __linux__
int ra_global;
int ra_kernel_set;
struct interface *find_interface(struct dhcpcd_ctx *, const char *);
int handle_args(struct dhcpcd_ctx *, struct fd_list *, int, char **);
-void handle_carrier(struct dhcpcd_ctx *, int, int, const char *);
+void handle_carrier(struct dhcpcd_ctx *, int, unsigned int, const char *);
void handle_interface(void *, int, const char *);
void handle_hwaddr(struct dhcpcd_ctx *, const char *,
- const unsigned char *, size_t);
+ const unsigned char *, uint8_t);
void drop_interface(struct interface *, const char *);
int select_profile(struct interface *, const char *);
/* time returns seconds from jan 1 1970, but DUID-LLT is
* seconds from jan 1 2000 modulo 2^32 */
t = time(NULL) - DUID_TIME_EPOCH;
- u32 = htonl(t & 0xffffffff);
+ u32 = htonl((uint32_t)t & 0xffffffff);
memcpy(p, &u32, 4);
p += 4;
}
/* Finally, add the MAC address of the interface */
memcpy(p, ifp->hwaddr, ifp->hwlen);
p += ifp->hwlen;
- return p - d;
+ return (size_t)(p - d);
}
#define DUID_STRLEN DUID_LEN * 3
#undef ADDADDR
#undef ADDSU
- rtm.hdr.rtm_msglen = l = bp - (char *)&rtm;
+ rtm.hdr.rtm_msglen = (unsigned short)(bp - (char *)&rtm);
- retval = write(s, &rtm, l) == -1 ? -1 : 0;
+ retval = write(s, &rtm, rtm.hdr.rtm_msglen) == -1 ? -1 : 0;
close(s);
return retval;
}
rtm.hdr.rtm_type = RTM_ADD;
else
rtm.hdr.rtm_type = RTM_DELETE;
- rtm.hdr.rtm_flags = RTF_UP | rt->flags;
+ rtm.hdr.rtm_flags = RTF_UP | (int)rt->flags;
rtm.hdr.rtm_addrs = RTA_DST | RTA_NETMASK;
#ifdef SIOCGIFPRIORITY
rtm.hdr.rtm_priority = rt->metric;
rtm.hdr.rtm_rmx.rmx_mtu = rt->mtu;
}
- rtm.hdr.rtm_msglen = l = bp - (char *)&rtm;
+ rtm.hdr.rtm_msglen = (unsigned short)(bp - (char *)&rtm);
- retval = write(s, &rtm, l) == -1 ? -1 : 0;
+ retval = write(s, &rtm, rtm.hdr.rtm_msglen) == -1 ? -1 : 0;
close(s);
return retval;
}
break;
}
handle_carrier(ctx, len,
- ifm->ifm_flags, ifname);
+ (unsigned int)ifm->ifm_flags, ifname);
break;
case RTM_DELETE:
if (~rtm->rtm_addrs &
int (*callback)(struct dhcpcd_ctx *, struct nlmsghdr *))
{
char *buf = NULL, *nbuf;
- ssize_t buflen = 0, bytes;
+ ssize_t bytes;
+ size_t buflen;
struct nlmsghdr *nlm;
struct sockaddr_nl nladdr;
socklen_t nladdr_len = sizeof(nladdr);
- int r = -1;
+ int r;
+ buflen = 0;
+ r = -1;
for (;;) {
bytes = recv(fd, NULL, 0,
flags | MSG_PEEK | MSG_DONTWAIT | MSG_TRUNC);
if (errno == EINTR)
continue;
goto eexit;
- } else if (bytes == buflen) {
+ } else if ((size_t)bytes == buflen) {
/* Support kernels older than 2.6.22 */
if (bytes == 0)
bytes = 512;
else
bytes *= 2;
}
- if (buflen < bytes) {
+ if (buflen < (size_t)bytes) {
/* Alloc 1 more so we work with older kernels */
- buflen = bytes + 1;
+ buflen = (size_t)bytes + 1;
nbuf = realloc(buf, buflen);
if (nbuf == NULL)
goto eexit;
err_netlink(__unused struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
{
struct nlmsgerr *err;
- int l;
+ size_t len;
if (nlm->nlmsg_type != NLMSG_ERROR)
return 0;
- l = nlm->nlmsg_len - sizeof(*nlm);
- if ((size_t)l < sizeof(*err)) {
+ len = nlm->nlmsg_len - sizeof(*nlm);
+ if (len < sizeof(*err)) {
errno = EBADMSG;
return -1;
}
err = (struct nlmsgerr *)NLMSG_DATA(nlm);
if (err->error == 0)
- return l;
+ return (int)len;
errno = -err->error;
return -1;
}
static int
link_route(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
{
- int len, idx, metric;
+ size_t len;
+ unsigned int idx, metric;
struct rtattr *rta;
struct rtmsg *rtm;
struct rt rt;
return 0;
len = nlm->nlmsg_len - sizeof(*nlm);
- if ((size_t)len < sizeof(*rtm)) {
+ if (len < sizeof(*rtm)) {
errno = EBADMSG;
return -1;
}
sizeof(rt.gate.s_addr));
break;
case RTA_OIF:
- idx = *(int *)RTA_DATA(rta);
+ idx = *(unsigned int *)RTA_DATA(rta);
if (if_indextoname(idx, ifn))
rt.iface = find_interface(ctx, ifn);
break;
case RTA_PRIORITY:
- metric = *(int *)RTA_DATA(rta);
+ metric = *(unsigned int *)RTA_DATA(rta);
break;
}
rta = RTA_NEXT(rta, len);
static int
link_addr(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
{
- int len;
+ size_t len;
struct rtattr *rta;
struct ifaddrmsg *ifa;
char ifn[IF_NAMESIZE + 1];
return 0;
len = nlm->nlmsg_len - sizeof(*nlm);
- if ((size_t)len < sizeof(*ifa)) {
+ if (len < sizeof(*ifa)) {
errno = EBADMSG;
return -1;
}
static int
link_netlink(struct dhcpcd_ctx *ctx, struct nlmsghdr *nlm)
{
- int len;
+ int r;
+ size_t len;
struct rtattr *rta, *hwaddr;
struct ifinfomsg *ifi;
char ifn[IF_NAMESIZE + 1];
struct interface *ifp;
- len = link_route(ctx, nlm);
- if (len != 0)
- return len;
- len = link_addr(ctx, nlm);
- if (len != 0)
- return len;
+ r = link_route(ctx, nlm);
+ if (r != 0)
+ return r;
+ r = link_addr(ctx, nlm);
+ if (r != 0)
+ return r;
if (nlm->nlmsg_type != RTM_NEWLINK && nlm->nlmsg_type != RTM_DELLINK)
return 0;
}
/* Check for interface name change */
- if (handle_rename(ctx, ifi->ifi_index, ifn))
+ if (handle_rename(ctx, (unsigned int)ifi->ifi_index, ifn))
return 1;
/* Check for a new interface */
/* Re-read hardware address and friends */
if (!(ifi->ifi_flags & IFF_UP) && hwaddr) {
- len = l2addr_len(ifi->ifi_type);
- if (hwaddr->rta_len == RTA_LENGTH(len))
- handle_hwaddr(ctx, ifn, RTA_DATA(hwaddr), len);
+ short l;
+
+ l = l2addr_len(ifi->ifi_type);
+ if (hwaddr->rta_len == RTA_LENGTH(l))
+ handle_hwaddr(ctx, ifn, RTA_DATA(hwaddr), l);
}
handle_carrier(ctx, ifi->ifi_flags & IFF_RUNNING ? LINK_UP : LINK_DOWN,
((struct rtattr *)(((ptrdiff_t)(nmsg))+NLMSG_ALIGN((nmsg)->nlmsg_len)))
static int
-add_attr_l(struct nlmsghdr *n, unsigned int maxlen, int type,
- const void *data, int alen)
+add_attr_l(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
+ const void *data, unsigned short alen)
{
- int len = RTA_LENGTH(alen);
+ unsigned short len = RTA_LENGTH(alen);
struct rtattr *rta;
if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
}
static int
-add_attr_32(struct nlmsghdr *n, unsigned int maxlen, int type, uint32_t data)
+add_attr_32(struct nlmsghdr *n, unsigned short maxlen, unsigned short type,
+ uint32_t data)
{
- int len = RTA_LENGTH(sizeof(data));
+ unsigned short len = RTA_LENGTH(sizeof(data));
struct rtattr *rta;
if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
nlm.ifa.ifa_prefixlen = inet_ntocidr(*netmask);
/* This creates the aliased interface */
add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL,
- iface->name, strlen(iface->name) + 1);
+ iface->name, (unsigned short)(strlen(iface->name) + 1));
add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL,
&address->s_addr, sizeof(address->s_addr));
if (action >= 0 && broadcast)
nlm.ifa.ifa_prefixlen = ap->prefix_len;
/* This creates the aliased interface */
add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LABEL,
- ap->iface->name, strlen(ap->iface->name) + 1);
+ ap->iface->name, (unsigned short)(strlen(ap->iface->name) + 1));
add_attr_l(&nlm.hdr, sizeof(nlm), IFA_LOCAL,
&ap->addr.s6_addr, sizeof(ap->addr.s6_addr));
}
static int
-rta_add_attr_32(struct rtattr *rta, unsigned int maxlen,
- int type, uint32_t data)
+rta_add_attr_32(struct rtattr *rta, unsigned short maxlen,
+ unsigned short type, uint32_t data)
{
- unsigned int len = RTA_LENGTH(sizeof(data));
+ unsigned short len = RTA_LENGTH(sizeof(data));
struct rtattr *subrta;
if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
subrta->rta_type = type;
subrta->rta_len = len;
memcpy(RTA_DATA(subrta), &data, sizeof(data));
- rta->rta_len = NLMSG_ALIGN(rta->rta_len) + len;
+ rta->rta_len = (unsigned short)(NLMSG_ALIGN(rta->rta_len) + len);
return 0;
}
#define parse_string(buf, len, arg) parse_string_hwaddr(buf, len, arg, 0)
static ssize_t
-parse_string_hwaddr(char *sbuf, ssize_t slen, const char *str, int clid)
+parse_string_hwaddr(char *sbuf, size_t slen, const char *str, int clid)
{
- ssize_t l;
+ size_t l;
const char *p;
int i, punt_last = 0;
char c[4];
if (*p == '"')
punt_last = 1;
} else {
- l = hwaddr_aton(NULL, str);
- if (l > 1) {
+ l = (size_t)hwaddr_aton(NULL, str);
+ if ((ssize_t) l != -1 && l > 1) {
if (l > slen) {
errno = ENOBUFS;
return -1;
}
hwaddr_aton((uint8_t *)sbuf, str);
- return l;
+ return (ssize_t)l;
}
}
}
if (c[1] != '\0' && sbuf) {
c[2] = '\0';
- *sbuf++ = strtol(c, NULL, 16);
+ *sbuf++ = (char)strtol(c, NULL, 16);
} else
l--;
break;
c[i] = *str++;
}
if (c[2] != '\0' && sbuf) {
- i = strtol(c, NULL, 8);
+ i = (int)strtol(c, NULL, 8);
if (i > 255)
i = 255;
- *sbuf ++= i;
+ *sbuf ++= (char)i;
} else
l--;
break;
*--sbuf = '\0';
l--;
}
- return l;
+ return (ssize_t)l;
}
static int
parse_iaid1(uint8_t *iaid, const char *arg, size_t len, int n)
{
unsigned long l;
- size_t s;
+ ssize_t s;
uint32_t u32;
char *np;
free(o);
return v;
}
- n = realloc(v, sizeof(char *) * ((*argc) + 1));
+ n = realloc(v, sizeof(char *) * ((size_t)(*argc) + 1));
if (n == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
free(o);
case 'u':
s = USERCLASS_MAX_LEN - ifo->userclass[0] - 1;
s = parse_string((char *)ifo->userclass +
- ifo->userclass[0] + 2,
- s, arg);
+ ifo->userclass[0] + 2, (size_t)s, arg);
if (s == -1) {
syslog(LOG_ERR, "userclass: %m");
return -1;
}
if (s != 0) {
- ifo->userclass[ifo->userclass[0] + 1] = s;
- ifo->userclass[0] += s + 1;
+ ifo->userclass[ifo->userclass[0] + 1] = (uint8_t)s;
+ ifo->userclass[0] += (uint8_t)s + 1;
}
break;
case 'v':
}
} else {
s = parse_string((char *)ifo->vendor +
- ifo->vendor[0] + 3, s, arg);
+ ifo->vendor[0] + 3, (size_t)s, arg);
}
if (s == -1) {
syslog(LOG_ERR, "vendor: %m");
return -1;
}
if (s != 0) {
- ifo->vendor[ifo->vendor[0] + 1] = i;
- ifo->vendor[ifo->vendor[0] + 2] = s;
- ifo->vendor[0] += s + 2;
+ ifo->vendor[ifo->vendor[0] + 1] = (uint8_t)i;
+ ifo->vendor[ifo->vendor[0] + 2] = (uint8_t)s;
+ ifo->vendor[0] += (uint8_t)s + 2;
}
break;
case 'w':
/* Commas to spaces for shell */
while ((p = strchr(arg, ',')))
*p = ' ';
- s = strlen("skip_hooks=") + strlen(arg) + 1;
- p = malloc(sizeof(char) * s);
+ dl = strlen("skip_hooks=") + strlen(arg) + 1;
+ p = malloc(sizeof(char) * dl);
if (p == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- snprintf(p, s, "skip_hooks=%s", arg);
+ snprintf(p, dl, "skip_hooks=%s", arg);
add_environ(ifo, p, 0);
free(p);
break;
}
TAILQ_INSERT_TAIL(ifo->routes, rt, next);
} else {
- s = 0;
+ dl = 0;
if (ifo->config != NULL) {
- while (ifo->config[s] != NULL) {
- if (strncmp(ifo->config[s], arg,
- p - arg) == 0)
+ while (ifo->config[dl] != NULL) {
+ if (strncmp(ifo->config[dl], arg,
+ (size_t)(p - arg)) == 0)
{
p = strdup(arg);
if (p == NULL) {
"%s: %m", __func__);
return -1;
}
- free(ifo->config[s]);
- ifo->config[s] = p;
+ free(ifo->config[dl]);
+ ifo->config[dl] = p;
return 1;
}
- s++;
+ dl++;
}
}
p = strdup(arg);
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- nconf = realloc(ifo->config, sizeof(char *) * (s + 2));
+ nconf = realloc(ifo->config, sizeof(char *) * (dl + 2));
if (nconf == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
ifo->config = nconf;
- ifo->config[s] = p;
- ifo->config[s + 1] = NULL;
+ ifo->config[dl] = p;
+ ifo->config[dl + 1] = NULL;
}
break;
case 'W':
syslog(LOG_ERR, "cannot specify a different IA type");
return -1;
}
- ifo->ia_type = i;
+ ifo->ia_type = (uint16_t)i;
if (arg == NULL)
break;
fp = strwhite(arg);
sla->sla_set = 0;
else {
errno = 0;
- sla->sla = atoint(p);
+ i = atoint(p);
+ if (i == -1)
+ goto err_sla;
+ sla->sla = (uint32_t)i;
if (sla->sla == 0 && ia->sla_len > 1) {
syslog(LOG_ERR, "%s: cannot"
" assign multiple prefixes"
goto err_sla;
}
if (np) {
- sla->prefix_len = atoint(np);
- if (sla->prefix_len < 0 ||
- sla->prefix_len > 128)
+ i = atoint(np);
+ if (i < 0 || i > 128)
goto err_sla;
+ sla->prefix_len = (uint8_t)i;
} else
sla->prefix_len = 64;
} else {
free_dhcp_opt_embenc(ndop);
ndop->option = u; /* could have been 0 */
ndop->type = t;
- ndop->len = l;
+ ndop->len = (size_t)l;
ndop->var = np;
/* Save the define for embed and encap options */
if (opt == O_DEFINE || opt == O_DEFINE6 || opt == O_VENDOPT)
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- if (s + (sizeof(uint16_t) * 2) > UINT16_MAX) {
+ dl = (size_t)s;
+ if (dl + (sizeof(uint16_t) * 2) > UINT16_MAX) {
syslog(LOG_ERR, "vendor class is too big");
return -1;
}
- np = malloc(s);
+ np = malloc(dl);
if (np == NULL) {
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
- parse_string(np, s, fp);
+ parse_string(np, dl, fp);
} else {
- s = 0;
+ dl = 0;
np = NULL;
}
vivco = realloc(ifo->vivco, sizeof(*ifo->vivco) *
ifo->vivco = vivco;
ifo->vivco_en = u;
vivco = &ifo->vivco[ifo->vivco_len++];
- vivco->len = s;
+ vivco->len = dl;
vivco->data = (uint8_t *)np;
break;
case O_AUTHPROTOCOL:
return -1;
}
*fp++ = '\0';
- token->realm_len = parse_string(NULL, 0, arg);
- if (token->realm_len) {
+ s = parse_string(NULL, 0, arg);
+ if (s == -1) {
+ syslog(LOG_ERR, "realm_len: %m");
+ return -1;
+ }
+ if (s) {
+ token->realm_len = (size_t)s;
token->realm = malloc(token->realm_len);
if (token->realm == NULL) {
free(token);
}
parse_string((char *)token->realm, token->realm_len,
arg);
+ } else {
+ token->realm_len = 0;
+ token->realm = NULL;
}
arg = fp;
fp = strend(arg);
}
}
arg = fp;
- token->key_len = parse_string(NULL, 0, arg);
- if (token->key_len == 0) {
- syslog(LOG_ERR, "authtoken needs a key");
+ s = parse_string(NULL, 0, arg);
+ if (s == -1 || s == 0) {
+ syslog(LOG_ERR, s == -1 ? "token_len: %m" :
+ "authtoken needs a key");
free(token->realm);
free(token);
return -1;
}
+ token->key_len = (size_t)s;
token->key = malloc(token->key_len);
parse_string((char *)token->key, token->key_len, arg);
TAILQ_INSERT_TAIL(&ifo->auth.tokens, token, next);
ifo->auth.options |= DHCPCD_AUTH_REQUIRE;
TAILQ_INIT(&ifo->auth.tokens);
- ifo->vendorclassid[0] = dhcp_vendor((char *)ifo->vendorclassid + 1,
+ ifo->vendorclassid[0] =
+ (uint8_t)dhcp_vendor((char *)ifo->vendorclassid + 1,
sizeof(ifo->vendorclassid) - 1);
buf = NULL;
struct if_sla {
char ifname[IF_NAMESIZE];
uint32_t sla;
- short prefix_len;
+ uint8_t prefix_len;
int8_t sla_set;
};
};
struct vivco {
- uint16_t len;
+ size_t len;
uint8_t *data;
};
char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
int fqdn;
uint8_t vendorclassid[VENDORCLASSID_MAX_LEN + 2];
- char clientid[CLIENTID_MAX_LEN + 2];
+ uint8_t clientid[CLIENTID_MAX_LEN + 2];
uint8_t userclass[USERCLASS_MAX_LEN + 2];
uint8_t vendor[VENDOR_MAX_LEN + 2];
#undef IPV4_LOOPBACK_ROUTE
#endif
-int
+uint8_t
inet_ntocidr(struct in_addr address)
{
- int cidr = 0;
+ uint8_t cidr = 0;
uint32_t mask = htonl(address.s_addr);
while (mask) {
struct in_addr net;
struct in_addr gate;
const struct interface *iface;
- int metric;
+ unsigned int metric;
struct in_addr src;
};
TAILQ_HEAD(rt_head, rt);
#ifdef INET
int ipv4_init(struct dhcpcd_ctx *);
-int inet_ntocidr(struct in_addr);
+uint8_t inet_ntocidr(struct in_addr);
int inet_cidrtoaddr(int, struct in_addr *);
uint32_t ipv4_getnetmask(uint32_t);
int ipv4_addrexists(struct dhcpcd_ctx *, const struct in_addr *);
int ipv4_opensocket(struct interface *, int);
ssize_t ipv4_sendrawpacket(const struct interface *,
- int, const void *, ssize_t);
-ssize_t ipv4_getrawpacket(struct interface *, int, void *, ssize_t, int *);
+ int, const void *, size_t);
+ssize_t ipv4_getrawpacket(struct interface *, int, void *, size_t, int *);
void ipv4_free(struct interface *);
void ipv4_ctxfree(struct dhcpcd_ctx *);
#else
}
ssize_t
-ipv6_printaddr(char *s, ssize_t sl, const uint8_t *d, const char *ifname)
+ipv6_printaddr(char *s, size_t sl, const uint8_t *d, const char *ifname)
{
char buf[INET6_ADDRSTRLEN];
const char *p;
- ssize_t l;
+ size_t l;
p = inet_ntop(AF_INET6, d, buf, sizeof(buf));
if (p == NULL)
l += 1 + strlen(ifname);
if (s == NULL)
- return l;
+ return (ssize_t)l;
if (sl < l) {
errno = ENOMEM;
s += strlcpy(s, ifname, sl);
}
*s = '\0';
- return l;
+ return (ssize_t)l;
}
int
bytelen = len / NBBY;
bitlen = len % NBBY;
- memcpy(&prefix->s6_addr, &addr->s6_addr, bytelen);
+ memcpy(&prefix->s6_addr, &addr->s6_addr, (size_t)bytelen);
if (bitlen != 0)
prefix->s6_addr[bytelen] >>= NBBY - bitlen;
memset((char *)prefix->s6_addr + bytelen, 0,
- sizeof(prefix->s6_addr) - bytelen);
+ sizeof(prefix->s6_addr) - (size_t)bytelen);
return 0;
}
return 0;
}
-int
+uint8_t
ipv6_prefixlen(const struct in6_addr *mask)
{
int x = 0, y;
*/
if (p < lim) {
if (y != 0 && (*p & (0x00ff >> y)) != 0)
- return -1;
+ return 0;
for (p = p + 1; p < lim; p++)
if (*p != 0)
- return -1;
+ return 0;
}
- return x * NBBY + y;
+ return (uint8_t)(x * NBBY + y);
}
static void
{
uint8_t *p = (uint8_t *)&add->s6_addr;
- p[0] = vhigh >> 56;
- p[1] = vhigh >> 48;
- p[2] = vhigh >> 40;
- p[3] = vhigh >> 32;
- p[4] = vhigh >> 24;
- p[5] = vhigh >> 16;
- p[6] = vhigh >> 8;
- p[7] = vhigh;
+ p[0] = (uint8_t)(vhigh >> 56);
+ p[1] = (uint8_t)(vhigh >> 48);
+ p[2] = (uint8_t)(vhigh >> 40);
+ p[3] = (uint8_t)(vhigh >> 32);
+ p[4] = (uint8_t)(vhigh >> 24);
+ p[5] = (uint8_t)(vhigh >> 16);
+ p[6] = (uint8_t)(vhigh >> 8);
+ p[7] = (uint8_t)vhigh;
p += 8;
- p[0] = vlow >> 56;
- p[1] = vlow >> 48;
- p[2] = vlow >> 40;
- p[3] = vlow >> 32;
- p[4] = vlow >> 24;
- p[5] = vlow >> 16;
- p[6] = vlow >> 8;
- p[7] = vlow;
+ p[0] = (uint8_t)(vlow >> 56);
+ p[1] = (uint8_t)(vlow >> 48);
+ p[2] = (uint8_t)(vlow >> 40);
+ p[3] = (uint8_t)(vlow >> 32);
+ p[4] = (uint8_t)(vlow >> 24);
+ p[5] = (uint8_t)(vlow >> 16);
+ p[6] = (uint8_t)(vlow >> 8);
+ p[7] = (uint8_t)vlow;
}
int
TAILQ_ENTRY(ipv6_addr) next;
struct interface *iface;
struct in6_addr prefix;
- int prefix_len;
+ uint8_t prefix_len;
uint32_t prefix_vltime;
uint32_t prefix_pltime;
struct in6_addr addr;
struct in6_addr gate;
const struct interface *iface;
unsigned int flags;
- int metric;
+ unsigned int metric;
unsigned int mtu;
};
TAILQ_HEAD(rt6_head, rt6);
#ifdef INET6
struct ipv6_ctx *ipv6_init(struct dhcpcd_ctx *);
-ssize_t ipv6_printaddr(char *, ssize_t, const uint8_t *, const char *);
+ssize_t ipv6_printaddr(char *, size_t, const uint8_t *, const char *);
int ipv6_makeaddr(struct in6_addr *, const struct interface *,
const struct in6_addr *, int);
int ipv6_makeprefix(struct in6_addr *, const struct in6_addr *, int);
int ipv6_mask(struct in6_addr *, int);
-int ipv6_prefixlen(const struct in6_addr *);
+uint8_t ipv6_prefixlen(const struct in6_addr *);
int ipv6_userprefix( const struct in6_addr *, short prefix_len,
uint64_t user_number, struct in6_addr *result, short result_len);
void ipv6_checkaddrflags(void *);
static void
ipv6nd_handlera(struct ipv6_ctx *ctx, struct interface *ifp,
- struct icmp6_hdr *icp, ssize_t len)
+ struct icmp6_hdr *icp, size_t len)
{
- ssize_t l, m, n, olen;
+ size_t olen, l, m, n;
+ ssize_t r;
struct nd_router_advert *nd_ra;
struct nd_opt_prefix_info *pi;
struct nd_opt_mtu *mtu;
struct timeval expire;
uint8_t new_rap, new_data;
- if ((size_t)len < sizeof(struct nd_router_advert)) {
+ if (len < sizeof(struct nd_router_advert)) {
syslog(LOG_ERR, "IPv6 RA packet too short from %s", ctx->sfrom);
return;
}
p = ((uint8_t *)icp) + sizeof(struct nd_router_advert);
lifetime = ~0U;
for (; len > 0; p += olen, len -= olen) {
- if ((size_t)len < sizeof(struct nd_opt_hdr)) {
+ if (len < sizeof(struct nd_opt_hdr)) {
syslog(LOG_ERR, "%s: short option", ifp->name);
break;
}
for (n = ndo->nd_opt_len - 1; n > 1; n -= 2,
op += sizeof(addr.s6_addr))
{
- m = ipv6_printaddr(NULL, 0, op, ifp->name);
- if (m != -1)
- l += m + 1;
+ r = ipv6_printaddr(NULL, 0, op, ifp->name);
+ if (r != -1)
+ l += (size_t)r + 1;
}
op = (uint8_t *)ndo;
op += offsetof(struct nd_opt_rdnss,
for (n = ndo->nd_opt_len - 1; n > 1; n -= 2,
op += sizeof(addr.s6_addr))
{
- m = ipv6_printaddr(tmp, l, op,
+ r = ipv6_printaddr(tmp, l, op,
ifp->name);
- if (m != -1) {
- l -= (m + 1);
- tmp += m;
+ if (r != -1) {
+ l -= ((size_t)r + 1);
+ tmp += (size_t)r;
*tmp++ = ' ';
}
}
nd_opt_dnssl_lifetime);
op += sizeof(dnssl->nd_opt_dnssl_lifetime);
n = (dnssl->nd_opt_dnssl_len - 1) * 8;
- l = decode_rfc3397(NULL, 0, n, op);
- if (l < 1) {
+ r = decode_rfc3397(NULL, 0, op, n);
+ if (r < 1) {
syslog(LOG_ERR, "%s: invalid DNSSL option",
ifp->name);
} else {
+ l = (size_t)r;
tmp = malloc(l);
if (tmp) {
- decode_rfc3397(tmp, l, n, op);
- n = print_string(NULL, 0,
- l - 1, (const uint8_t *)tmp);
+ decode_rfc3397(tmp, l, op, n);
+ l -= 1;
+ n = (size_t)print_string(NULL, 0,
+ (const uint8_t *)tmp, l);
opt = malloc(n);
if (opt)
print_string(opt, n,
- l - 1,
- (const uint8_t *)tmp);
+ (const uint8_t *)tmp, l);
free(tmp);
}
}
ssize_t
ipv6nd_env(char **env, const char *prefix, const struct interface *ifp)
{
- ssize_t l;
- size_t len;
+ size_t i, len, l;
const struct ra *rap;
const struct ra_opt *rao;
- int i;
char buffer[32];
const char *optn;
char **pref, **mtu, **rdnss, **dnssl, ***var, *new;
- i = 0;
- l = 0;
+ i = l = 0;
TAILQ_FOREACH(rap, ifp->ctx->ipv6->ra_routers, next) {
i++;
if (rap->iface != ifp)
if (env) {
snprintf(buffer, sizeof(buffer),
"ra%d_from", i);
- if (setvar(&env, prefix, buffer, rap->sfrom) == -1)
- return -1;
+ setvar(&env, prefix, buffer, rap->sfrom);
}
l++;
continue;
} else
new++;
- len = (new - **var) +
+ len = (size_t)(new - **var) +
strlen(rao->option) + 1;
if (len > strlen(**var))
new = realloc(**var, len);
**var = new;
new = strchr(**var, '=');
if (new) {
- len -= (new - **var);
+ len -=
+ (size_t)
+ (new - **var);
strlcpy(new + 1,
rao->option,
len - 1);
}
len = strlen(rao->option) + 1;
new = realloc(**var, strlen(**var) + 1 + len);
- if (new == NULL)
- return -1;
- **var = new;
- new += strlen(new);
- *new++ = ' ';
- strlcpy(new, rao->option, len);
+ if (new) {
+ **var = new;
+ new += strlen(new);
+ *new++ = ' ';
+ strlcpy(new, rao->option, len);
+ } else
+ syslog(LOG_ERR, "%s: %m", __func__);
continue;
}
if (env) {
snprintf(buffer, sizeof(buffer),
"ra%d_%s", i, optn);
- if (setvar(&env, prefix, buffer, rao->option)
- == -1)
- return -1;
+ setvar(&env, prefix, buffer, rao->option);
}
}
}
- if (env) {
- if (setvard(&env, prefix, "ra_count", i) == -1)
- return -1;
- }
+ if (env)
+ setvard(&env, prefix, "ra_count", i);
l++;
- return l;
+ return (ssize_t)l;
}
void
static void
ipv6nd_handlena(struct ipv6_ctx *ctx, struct interface *ifp,
- struct icmp6_hdr *icp, ssize_t len)
+ struct icmp6_hdr *icp, size_t len)
{
struct nd_neighbor_advert *nd_na;
struct ra *rap;
if (icp->icmp6_code == 0) {
switch(icp->icmp6_type) {
case ND_NEIGHBOR_ADVERT:
- ipv6nd_handlena(ctx, ifp, icp, len);
+ ipv6nd_handlena(ctx, ifp, icp, (size_t)len);
return;
case ND_ROUTER_ADVERT:
- ipv6nd_handlera(ctx, ifp, icp, len);
+ ipv6nd_handlera(ctx, ifp, icp, (size_t)len);
return;
}
}
struct in6_addr from;
char sfrom[INET6_ADDRSTRLEN];
unsigned char *data;
- ssize_t data_len;
+ size_t data_len;
struct timeval received;
unsigned char flags;
uint32_t lifetime;
memset(&su, 0, sizeof(su));
su.sll.sll_family = PF_PACKET;
su.sll.sll_protocol = htons(protocol);
- su.sll.sll_ifindex = ifp->index;
+ su.sll.sll_ifindex = (int)ifp->index;
/* Install the DHCP filter */
memset(&pf, 0, sizeof(pf));
if (protocol == ETHERTYPE_ARP) {
pf.filter = UNCONST(arp_bpf_filter);
- pf.len = arp_bpf_filter_len;
+ pf.len = (unsigned int)arp_bpf_filter_len;
} else {
pf.filter = UNCONST(dhcp_bpf_filter);
- pf.len = dhcp_bpf_filter_len;
+ pf.len = (unsigned int)dhcp_bpf_filter_len;
}
if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER, &pf, sizeof(pf)) != 0)
goto eexit;
ssize_t
ipv4_sendrawpacket(const struct interface *ifp, int protocol,
- const void *data, ssize_t len)
+ const void *data, size_t len)
{
const struct dhcp_state *state;
union sockunion {
memset(&su, 0, sizeof(su));
su.sll.sll_family = AF_PACKET;
su.sll.sll_protocol = htons(protocol);
- su.sll.sll_ifindex = ifp->index;
+ su.sll.sll_ifindex = (int)ifp->index;
su.sll.sll_hatype = htons(ifp->family);
- su.sll.sll_halen = ifp->hwlen;
+ su.sll.sll_halen = (unsigned char)ifp->hwlen;
if (ifp->family == ARPHRD_INFINIBAND)
memcpy(&su.sll.sll_addr,
&ipv4_bcast_addr, sizeof(ipv4_bcast_addr));
ssize_t
ipv4_getrawpacket(struct interface *ifp, int protocol,
- void *data, ssize_t len, int *partialcsum)
+ void *data, size_t len, int *partialcsum)
{
struct iovec iov = {
.iov_base = data,
close(s);
return LINK_UNKNOWN;
}
- iface->flags = ifr.ifr_flags;
+ iface->flags = (unsigned int)ifr.ifr_flags;
r = LINK_UNKNOWN;
#ifdef SIOCGIFMEDIA
if (ioctl(s, SIOCSIFFLAGS, &ifr) == 0)
r = 0;
}
- iface->flags = ifr.ifr_flags;
+ iface->flags = (unsigned int)ifr.ifr_flags;
}
close(s);
return r;
{
struct ifaddrs *ifaddrs, *ifa;
char *p;
- int i, sdl_type;
+ int i;
+ sa_family_t sdl_type;
struct if_head *ifs;
struct interface *ifp;
#ifdef __linux__
memcpy(ifp->hwaddr, CLLADDR(sdl), ifp->hwlen);
#elif AF_PACKET
sll = (const struct sockaddr_ll *)(void *)ifa->ifa_addr;
- ifp->index = sll->sll_ifindex;
+ ifp->index = (unsigned int)sll->sll_ifindex;
ifp->family = sdl_type = sll->sll_hatype;
ifp->hwlen = sll->sll_halen;
if (ifp->hwlen != 0)
if (ifname) {
#ifdef ND6_IFF_ACCEPT_RTADV
- int i;
+ size_t i;
char *p, **nrest;
#endif
int
check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
{
- int ra, i;
+ int ra;
+ size_t i;
char path[256], *p, **nrest;
if (ifname == NULL)
static int
-append_config(char ***env, ssize_t *len,
+append_config(char ***env, size_t *len,
const char *prefix, const char *const *config)
{
- ssize_t i, j, e1;
+ size_t i, j, e1;
char **ne, *eq, **nep, *p;
int ret;
ret = 0;
for (i = 0; config[i] != NULL; i++) {
eq = strchr(config[i], '=');
- e1 = eq - config[i] + 1;
+ e1 = (size_t)(eq - config[i] + 1);
for (j = 0; j < *len; j++) {
if (strncmp(ne[j] + strlen(prefix) + 1,
config[i], e1) == 0)
}
#endif
-static size_t
+static ssize_t
arraytostr(const char *const *argv, char **s)
{
const char *const *ap;
p += l;
ap++;
}
- return len;
+ return (ssize_t)len;
}
static ssize_t
make_env(const struct interface *ifp, const char *reason, char ***argv)
{
char **env, **nenv, *p;
- ssize_t e, elen, l;
+ size_t e, elen, l;
+ ssize_t n;
const struct if_options *ifo = ifp->options;
const struct interface *ifp2;
#ifdef INET
else
elen = 11;
-#define EMALLOC(i, l) if ((env[(i)] = malloc(l)) == NULL) goto eexit;
+#define EMALLOC(i, l) if ((env[(i)] = malloc((l))) == NULL) goto eexit;
/* Make our env */
env = calloc(1, sizeof(char *) * (elen + 1));
if (env == NULL)
}
#ifdef INET
if (dhcp && state && state->old) {
- e = dhcp_env(NULL, NULL, state->old, ifp);
- if (e > 0) {
- nenv = realloc(env, sizeof(char *) * (elen + e + 1));
+ n = dhcp_env(NULL, NULL, state->old, ifp);
+ if (n == -1)
+ goto eexit;
+ if (n > 0) {
+ nenv = realloc(env, sizeof(char *) *
+ (elen + (size_t)n + 1));
if (nenv == NULL)
goto eexit;
env = nenv;
- l = dhcp_env(env + elen, "old", state->old, ifp);
- if (l == -1)
+ n = dhcp_env(env + elen, "old", state->old, ifp);
+ if (n == -1)
goto eexit;
- elen += l;
+ elen += (size_t)n;
}
if (append_config(&env, &elen, "old",
(const char *const *)ifo->config) == -1)
#endif
#ifdef INET6
if (dhcp6 && d6_state && d6_state->old) {
- e = dhcp6_env(NULL, NULL, ifp,
+ n = dhcp6_env(NULL, NULL, ifp,
d6_state->old, d6_state->old_len);
- if (e > 0) {
- nenv = realloc(env, sizeof(char *) * (elen + e + 1));
+ if (n > 0) {
+ nenv = realloc(env, sizeof(char *) *
+ (elen + (size_t)n + 1));
if (nenv == NULL)
goto eexit;
env = nenv;
- l = dhcp6_env(env + elen, "old", ifp,
+ n = dhcp6_env(env + elen, "old", ifp,
d6_state->old, d6_state->old_len);
- if (l == -1)
+ if (n == -1)
goto eexit;
- elen += l;
+ elen += (size_t)n;
}
}
#endif
dumplease:
#ifdef INET
if (dhcp && state && state->new) {
- e = dhcp_env(NULL, NULL, state->new, ifp);
+ n = dhcp_env(NULL, NULL, state->new, ifp);
if (e > 0) {
- nenv = realloc(env, sizeof(char *) * (elen + e + 1));
+ nenv = realloc(env, sizeof(char *) *
+ (elen + (size_t)n + 1));
if (nenv == NULL)
goto eexit;
env = nenv;
- l = dhcp_env(env + elen, "new",
+ n = dhcp_env(env + elen, "new",
state->new, ifp);
- if (l == -1)
+ if (n == -1)
goto eexit;
- elen += l;
+ elen += (size_t)n;
}
if (append_config(&env, &elen, "new",
(const char *const *)ifo->config) == -1)
#endif
#ifdef INET6
if (dhcp6 && d6_state && d6_state->new) {
- e = dhcp6_env(NULL, NULL, ifp,
+ n = dhcp6_env(NULL, NULL, ifp,
d6_state->new, d6_state->new_len);
- if (e > 0) {
- nenv = realloc(env, sizeof(char *) * (elen + e + 1));
+ if (n > 0) {
+ nenv = realloc(env, sizeof(char *) *
+ (elen + (size_t)n + 1));
if (nenv == NULL)
goto eexit;
env = nenv;
- l = dhcp6_env(env + elen, "new", ifp,
+ n = dhcp6_env(env + elen, "new", ifp,
d6_state->new, d6_state->new_len);
- if (l == -1)
+ if (n == -1)
goto eexit;
- elen += l;
+ elen += (size_t)n;
}
}
if (ra) {
- e = ipv6nd_env(NULL, NULL, ifp);
- if (e > 0) {
- nenv = realloc(env, sizeof(char *) * (elen + e + 1));
+ n = ipv6nd_env(NULL, NULL, ifp);
+ if (n > 0) {
+ nenv = realloc(env, sizeof(char *) *
+ (elen + (size_t)n + 1));
if (nenv == NULL)
goto eexit;
env = nenv;
- l = ipv6nd_env(env + elen, NULL, ifp);
- if (l == -1)
+ n = ipv6nd_env(env + elen, NULL, ifp);
+ if (n == -1)
goto eexit;
- elen += l;
+ elen += (size_t)n;
}
}
#endif
env[elen] = NULL;
*argv = env;
- return elen;
+ return (ssize_t)elen;
eexit:
syslog(LOG_ERR, "%s: %m", __func__);
return -1;
}
-static int
+static ssize_t
send_interface1(int fd, const struct interface *iface, const char *reason)
{
char **env, **ep, *s;
- ssize_t elen;
+ size_t elen;
struct iovec iov[2];
- int retval;
+ ssize_t retval;
if (make_env(iface, reason, &env) == -1)
return -1;
- elen = arraytostr((const char *const *)env, &s);
- if (elen == -1)
+ elen = (size_t)arraytostr((const char *const *)env, &s);
+ if ((ssize_t)elen == -1)
return -1;
iov[0].iov_base = &elen;
iov[0].iov_len = sizeof(ssize_t);
char *argv[2];
char **env = NULL, **ep;
char *path, *bigenv;
- ssize_t e, elen = 0;
+ size_t e, elen = 0;
pid_t pid;
int status = 0;
const struct fd_list *fd;
ifp->name, argv[0], reason);
/* Make our env */
- elen = make_env(ifp, reason, &env);
+ elen = (size_t)make_env(ifp, reason, &env);
+ if (elen == (size_t)-1) {
+ syslog(LOG_ERR, "%s: make_env: %m", ifp->name);
+ return -1;
+ }
ep = realloc(env, sizeof(char *) * (elen + 2));
if (ep == NULL) {
- elen = -1;
+ elen = 0;
goto out;
}
env = ep;
e = strlen("PATH") + strlen(path) + 2;
env[elen] = malloc(e);
if (env[elen] == NULL) {
- elen = -1;
+ elen = 0;
goto out;
}
snprintf(env[elen], e, "PATH=%s", path);
} else {
env[elen] = strdup(DEFAULT_PATH);
if (env[elen] == NULL) {
- elen = -1;
+ elen = 0;
goto out;
}
}
for (fd = ifp->ctx->control_fds; fd != NULL; fd = fd->next) {
if (fd->listener) {
if (bigenv == NULL) {
- elen = arraytostr((const char *const *)env,
+ elen = (size_t)arraytostr((const char *const *)env,
&bigenv);
+ if ((ssize_t)elen == -1) {
+ syslog(LOG_ERR, "%s: arraytostr: %m",
+ ifp->name);
+ continue;
+ }
iov[0].iov_base = &elen;
- iov[0].iov_len = sizeof(ssize_t);
+ iov[0].iov_len = sizeof(size_t);
iov[1].iov_base = bigenv;
iov[1].iov_len = elen;
}
while (*ep)
free(*ep++);
free(env);
- if (elen == -1)
+ if (elen == 0)
return -1;
return WEXITSTATUS(status);
}