]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix compile warnings with prior.
authorRoy Marples <roy@marples.name>
Tue, 12 May 2020 09:58:31 +0000 (10:58 +0100)
committerRoy Marples <roy@marples.name>
Tue, 12 May 2020 09:58:31 +0000 (10:58 +0100)
src/dhcp-common.c
src/dhcp.c
src/dhcp6.c
src/if-options.c
src/privsep-root.c
src/privsep-root.h

index b3e9c1e03f2a49745ff46dc7ba3fb5a24a94d662..daf9dd3f79d08d38a98f2095434b2d7c31fb577a 100644 (file)
@@ -983,7 +983,7 @@ dhcp_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
 #ifdef PRIVSEP
        if (ctx->options & DHCPCD_PRIVSEP &&
            !(ctx->options & DHCPCD_PRIVSEPROOT))
-               return ps_root_filemtime(ctx, file, time);
+               return (int)ps_root_filemtime(ctx, file, time);
 #else
        UNUSED(ctx);
 #endif
@@ -998,7 +998,7 @@ dhcp_unlink(struct dhcpcd_ctx *ctx, const char *file)
 #ifdef PRIVSEP
        if (ctx->options & DHCPCD_PRIVSEP &&
            !(ctx->options & DHCPCD_PRIVSEPROOT))
-               return ps_root_unlink(ctx, file);
+               return (int)ps_root_unlink(ctx, file);
 #else
        UNUSED(ctx);
 #endif
index d9683a9313631a6b7438f138abe309aa5da10ac0..6417f7f56cdbde12d74616cb784d378248dddcdf 100644 (file)
@@ -1150,7 +1150,8 @@ read_lease(struct interface *ifp, struct bootp **bootp)
        } buf;
        struct dhcp_state *state = D_STATE(ifp);
        struct bootp *lease;
-       ssize_t bytes;
+       ssize_t sbytes;
+       size_t bytes;
        uint8_t type;
 #ifdef AUTH
        const uint8_t *auth;
@@ -1162,25 +1163,26 @@ read_lease(struct interface *ifp, struct bootp **bootp)
 
        if (state->leasefile[0] == '\0') {
                logdebugx("reading standard input");
-               bytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
+               sbytes = read(fileno(stdin), buf.buf, sizeof(buf.buf));
        } else {
                logdebugx("%s: reading lease `%s'",
                    ifp->name, state->leasefile);
-               bytes = dhcp_readfile(ifp->ctx, state->leasefile,
+               sbytes = dhcp_readfile(ifp->ctx, state->leasefile,
                    buf.buf, sizeof(buf.buf));
        }
-       if (bytes == -1) {
+       if (sbytes == -1) {
                if (errno != ENOENT)
                        logerr("%s: %s", ifp->name, state->leasefile);
                return 0;
        }
+       bytes = (size_t)sbytes;
 
        /* Ensure the packet is at lease BOOTP sized
         * with a vendor area of 4 octets
         * (it should be more, and our read packet enforces this so this
         * code should not be needed, but of course people could
         * scribble whatever in the stored lease file. */
-       if ((size_t)bytes < DHCP_MIN_LEN) {
+       if (bytes < DHCP_MIN_LEN) {
                logerrx("%s: %s: truncated lease", ifp->name, __func__);
                return 0;
        }
@@ -1224,7 +1226,7 @@ out:
                return 0;
        }
        memcpy(*bootp, buf.buf, bytes);
-       return (size_t)bytes;
+       return bytes;
 }
 
 static const struct dhcp_opt *
index f46ba42491e6468c2cdfa8ac2fe42982722fbd21..6bc3e62750198eb28d4f3d03310da7c41487d550 100644 (file)
@@ -2632,7 +2632,7 @@ dhcp6_readlease(struct interface *ifp, int validate)
        state->acquired.tv_sec -= now - mtime;
 
        /* Check to see if the lease is still valid */
-       fd = dhcp6_validatelease(ifp, &buf.dhcp6, bytes, NULL,
+       fd = dhcp6_validatelease(ifp, &buf.dhcp6, (size_t)bytes, NULL,
            &state->acquired);
        if (fd == -1)
                goto ex;
@@ -2649,10 +2649,10 @@ dhcp6_readlease(struct interface *ifp, int validate)
 auth:
 #ifdef AUTH
        /* Authenticate the message */
-       o = dhcp6_findmoption(&buf.dhcp6, bytes, D6_OPTION_AUTH, &ol);
+       o = dhcp6_findmoption(&buf.dhcp6, (size_t)bytes, D6_OPTION_AUTH, &ol);
        if (o) {
                if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
-                   buf.buf, bytes, 6, buf.dhcp6.type, o, ol) == NULL)
+                   buf.buf, (size_t)bytes, 6, buf.dhcp6.type, o, ol) == NULL)
                {
                        logerr("%s: authentication failed", ifp->name);
                        bytes = 0;
@@ -2673,14 +2673,14 @@ auth:
 
 out:
        free(state->new);
-       state->new = malloc(bytes);
+       state->new = malloc((size_t)bytes);
        if (state->new == NULL) {
                logerr(__func__);
                goto ex;
        }
 
-       memcpy(state->new, buf.buf, bytes);
-       state->new_len = bytes;
+       memcpy(state->new, buf.buf, (size_t)bytes);
+       state->new_len = (size_t)bytes;
        return bytes;
 
 ex:
index 4ed38a987731a3c6b4d724be45cba62020bb95b4..329a3b2e4c32d10d97fe7a0c5a755fb91010412b 100644 (file)
@@ -2271,9 +2271,9 @@ get_line(char ** __restrict buf, ssize_t * __restrict buflen)
 
        do {
                p = *buf;
-               c = memchr(*buf, '\n', *buflen);
+               c = memchr(*buf, '\n', (size_t)*buflen);
                if (c == NULL) {
-                       c = memchr(*buf, '\0', *buflen);
+                       c = memchr(*buf, '\0', (size_t)*buflen);
                        if (c == NULL)
                                return NULL;
                        *buflen = c - *buf;
@@ -2342,7 +2342,7 @@ read_config(struct dhcpcd_ctx *ctx,
        char buf[UDPLEN_MAX], *bp; /* 64k max config file size */
        char *line, *option, *p;
        ssize_t buflen;
-       ssize_t vlen;
+       size_t vlen;
        int skip, have_profile, new_block, had_block;
 #if !defined(INET) || !defined(INET6)
        size_t i;
@@ -2415,7 +2415,8 @@ read_config(struct dhcpcd_ctx *ctx,
                        buf[buflen] = '\0';
                }
 #else
-               buflen = strlcpy(buf, dhcpcd_embedded_conf, sizeof(buf));
+               buflen = (ssize_t)strlcpy(buf, dhcpcd_embedded_conf,
+                   sizeof(buf));
                if ((size_t)buflen >= sizeof(buf)) {
                        logerrx("%s: embedded config too big", __func__);
                        return ifo;
index 0bcaf5007645cdff78456506326e6eecc4d02743..fb3c3253354e899ca43627163a2cc954b8a94e75 100644 (file)
@@ -228,7 +228,7 @@ ps_root_dowritefile(mode_t mode, void *data, size_t len)
                return -1;
        }
        nc++;
-       return writefile(file, mode, nc, len - (nc - file));
+       return writefile(file, mode, nc, len - (size_t)(nc - file));
 }
 
 static ssize_t
@@ -317,7 +317,7 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg)
                }
                break;
        case PS_WRITEFILE:
-               err = ps_root_dowritefile(psm->ps_flags, data, len);
+               err = ps_root_dowritefile((mode_t)psm->ps_flags, data, len);
                break;
        case PS_FILEMTIME:
                err = filemtime(data, &mtime);
@@ -547,7 +547,7 @@ ps_root_writefile(struct dhcpcd_ctx *ctx, const char *file, mode_t mode,
        return ps_root_readerror(ctx, NULL, 0);
 }
 
-int
+ssize_t
 ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
 {
 
index a5fdb2520b0d481d01f3ac416cb07a9c573551d7..d1a1b54be5ef607f0b439538f4c743e895e177eb 100644 (file)
@@ -37,7 +37,7 @@ int ps_root_stop(struct dhcpcd_ctx *ctx);
 ssize_t ps_root_readerror(struct dhcpcd_ctx *, void *, size_t);
 ssize_t ps_root_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
 ssize_t ps_root_unlink(struct dhcpcd_ctx *, const char *);
-int ps_root_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
+ssize_t ps_root_filemtime(struct dhcpcd_ctx *, const char *, time_t *);
 ssize_t ps_root_readfile(struct dhcpcd_ctx *, const char *, void *, size_t);
 ssize_t ps_root_writefile(struct dhcpcd_ctx *, const char *, mode_t,
     const void *, size_t);