]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix some issues reported by Converity.
authorRoy Marples <roy@marples.name>
Tue, 3 May 2016 10:14:14 +0000 (10:14 +0000)
committerRoy Marples <roy@marples.name>
Tue, 3 May 2016 10:14:14 +0000 (10:14 +0000)
dhcp.c
dhcp.h
dhcp6.c

diff --git a/dhcp.c b/dhcp.c
index e3d1de999f8b7a84ad6a03472933dcb21d3c10d4..f759948213bd080a16880a80203e5622e0205e0d 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -198,7 +198,7 @@ get_option(struct dhcpcd_ctx *ctx,
                }
                l = *p++;
 
-               if (o == DHO_OPTIONSOVERLOADED) {
+               if (o == DHO_OPTSOVERLOADED) {
                        /* Ensure we only get this option once by setting
                         * the last bit as well as the value.
                         * This is valid because only the first two bits
@@ -1139,11 +1139,13 @@ read_lease(struct interface *ifp)
                    ifp->name, state->leasefile);
        dhcp = calloc(1, sizeof(*dhcp));
        if (dhcp == NULL) {
-               close(fd);
+               if (state->leasefile[0] != '\0')
+                       close(fd);
                return NULL;
        }
        bytes = read(fd, dhcp, sizeof(*dhcp));
-       close(fd);
+       if (state->leasefile[0] != '\0')
+               close(fd);
        if (bytes < 0) {
                free(dhcp);
                return NULL;
@@ -1254,7 +1256,8 @@ dhcp_env(char **env, const char *prefix, const struct dhcp_message *dhcp,
 
        e = 0;
        ifo = ifp->options;
-       get_option_uint8(ifp->ctx, &overl, dhcp, DHO_OPTIONSOVERLOADED);
+       if (get_option_uint8(ifp->ctx, &overl, dhcp, DHO_OPTSOVERLOADED) == -1)
+               overl = 0;
 
        if (env == NULL) {
                if (dhcp->yiaddr || dhcp->ciaddr)
@@ -2008,6 +2011,7 @@ dhcp_arp_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
                arp_free(astate);
                eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
                dhcpcd_startinterface(ifp);
+               return;
        }
 
        /* RFC 2131 3.1.5, Client-server interaction
@@ -2039,6 +2043,7 @@ dhcp_arp_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
                eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
                eloop_timeout_add_sec(ifp->ctx->eloop,
                    DHCP_RAND_MAX, dhcp_discover, ifp);
+               return;
        }
 
        /* Bound address */
@@ -2054,6 +2059,7 @@ dhcp_arp_conflicted(struct arp_state *astate, const struct arp_msg *amsg)
                        arp_free(astate);
                        dhcp_expire1(ifp);
                }
+               return;
        }
 }
 
diff --git a/dhcp.h b/dhcp.h
index f5f9e52f2d0e21b1c784acad6d74e1a6d3dea0af..a400d07d8094f44bfef8a07d50ede1fe0c1c379c 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -95,7 +95,7 @@ enum DHO {
        DHO_VENDOR                 = 43,
        DHO_IPADDRESS              = 50,
        DHO_LEASETIME              = 51,
-       DHO_OPTIONSOVERLOADED      = 52,
+       DHO_OPTSOVERLOADED         = 52,
        DHO_MESSAGETYPE            = 53,
        DHO_SERVERID               = 54,
        DHO_PARAMETERREQUESTLIST   = 55,
diff --git a/dhcp6.c b/dhcp6.c
index 80a12310741ddaa75d695b77441c765594a992fe..391d5c6b3ef536011cbb770f54b7659b591dd4df 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -2176,13 +2176,19 @@ dhcp6_readlease(struct interface *ifp, int validate)
        } else {
                logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
                    ifp->name, state->leasefile);
-               fd = open(state->leasefile, O_RDONLY);
+               if (stat(state->leasefile, &st) == -1)
+                       fd = -1;
+               else
+                       fd = open(state->leasefile, O_RDONLY);
        }
        if (fd == -1)
                return -1;
        state->new_len = 0;
-       if ((state->new = malloc(BUFSIZ)) == NULL)
+       if ((state->new = malloc(BUFSIZ)) == NULL) {
+               if (state->leasefile[0] != '\0')
+                       close(fd);
                return -1;
+       }
        retval = -1;
        /* DHCPv6 messages have no real maximum size.
         * As we could be reading from stdin, we loop like so. */
@@ -2205,11 +2211,13 @@ dhcp6_readlease(struct interface *ifp, int validate)
                state->new = newnew;
                state->new_len = newlen;
        }
-       close(fd);
+       if (state->leasefile[0] != '\0')
+               close(fd);
        if (retval == -1)
                goto ex;
 
-       if (ifp->ctx->options & DHCPCD_DUMPLEASE)
+       if (ifp->ctx->options & DHCPCD_DUMPLEASE ||
+           state->leasefile[0] == '\0')
                return 0;
 
        /* If not validating IA's and if they have expired,
@@ -2220,8 +2228,6 @@ dhcp6_readlease(struct interface *ifp, int validate)
        }
 
        retval = -1;
-       if (stat(state->leasefile, &st) == -1)
-               goto ex;
        clock_gettime(CLOCK_MONOTONIC, &acquired);
        if ((now = time(NULL)) == -1)
                goto ex;
@@ -2282,7 +2288,8 @@ ex:
        free(state->new);
        state->new = NULL;
        state->new_len = 0;
-       if (!(ifp->ctx->options & DHCPCD_DUMPLEASE))
+       if (!(ifp->ctx->options & DHCPCD_DUMPLEASE) &&
+           state->leasefile[0] != '\0')
                unlink(state->leasefile);
        return retval;
 }