]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix more clang analyzer warnings. i386/NetBSD and amd64/Linux are now clear.
authorRoy Marples <roy@marples.name>
Fri, 28 Feb 2014 10:34:05 +0000 (10:34 +0000)
committerRoy Marples <roy@marples.name>
Fri, 28 Feb 2014 10:34:05 +0000 (10:34 +0000)
dhcp.c
dhcp6.c

diff --git a/dhcp.c b/dhcp.c
index 19e83901efe639713090b26145f3b710128179f1..18d82d1d0ba63fe98d76621a8bce2a75b5aaba02 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -1453,8 +1453,8 @@ checksum(const void *data, uint16_t len)
        return ~sum;
 }
 
-static ssize_t
-dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length,
+static struct udp_dhcp_packet *
+dhcp_makeudppacket(ssize_t *sz, const uint8_t *data, size_t length,
        struct in_addr source, struct in_addr dest)
 {
        struct udp_dhcp_packet *udpp;
@@ -1463,7 +1463,7 @@ dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length,
 
        udpp = calloc(1, sizeof(*udpp));
        if (udpp == NULL)
-               return -1;
+               return NULL;
        ip = &udpp->ip;
        udp = &udpp->udp;
 
@@ -1498,8 +1498,8 @@ dhcp_makeudppacket(uint8_t **p, const uint8_t *data, size_t length,
        ip->ip_len = htons(sizeof(*ip) + sizeof(*udp) + length);
        ip->ip_sum = checksum(ip, sizeof(*ip));
 
-       *p = (uint8_t *)udpp;
-       return sizeof(*ip) + sizeof(*udp) + length;
+       *sz = sizeof(*ip) + sizeof(*udp) + length;
+       return udpp;
 }
 
 static void
@@ -1568,11 +1568,14 @@ send_message(struct interface *iface, int type,
                        dhcp_close(iface);
                }
        } else {
-               len = dhcp_makeudppacket(&udp, (uint8_t *)dhcp, len, from, to);
-               if (len == -1)
-                       return;
-               r = ipv4_sendrawpacket(iface, ETHERTYPE_IP, udp, len);
-               free(udp);
+               r = 0;
+               udp = dhcp_makeudppacket(&r, (uint8_t *)dhcp, len, from, to);
+               if (udp == NULL) {
+                       syslog(LOG_ERR, "dhcp_makeudppacket: %m");
+               } else {
+                       r = ipv4_sendrawpacket(iface, ETHERTYPE_IP, udp, r);
+                       free(udp);
+               }
                /* If we failed to send a raw packet this normally means
                 * we don't have the ability to work beneath the IP layer
                 * for this interface.
diff --git a/dhcp6.c b/dhcp6.c
index de3452a0851817237e5b6a0bbbeca9731d91df84..56e9100d0d5af94e519afea732c5501f72ecb1da 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -1356,7 +1356,9 @@ dhcp6_findna(struct interface *ifp, const uint8_t *iaid,
                            iabuf, sizeof(iabuf));
                        snprintf(a->saddr, sizeof(a->saddr),
                            "%s/%d", ia, a->prefix_len);
-               }
+                       TAILQ_INSERT_TAIL(&state->addrs, a, next);
+               } else
+                       a->flags &= ~IPV6_AF_STALE;
                memcpy(&u32, p, sizeof(u32));
                a->prefix_pltime = ntohl(u32);
                p += sizeof(u32);
@@ -1370,10 +1372,6 @@ dhcp6_findna(struct interface *ifp, const uint8_t *iaid,
                    state->lowpl = a->prefix_pltime;
                if (a->prefix_vltime && a->prefix_vltime > state->expire)
                    state->expire = a->prefix_vltime;
-               if (a->flags & IPV6_AF_STALE)
-                       a->flags &= ~IPV6_AF_STALE;
-               else
-                       TAILQ_INSERT_TAIL(&state->addrs, a, next);
                i++;
        }
        return i;
@@ -1441,8 +1439,12 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                            iabuf, sizeof(iabuf));
                        snprintf(a->saddr, sizeof(a->saddr),
                            "%s/%d", ia, a->prefix_len);
-               } else if (a->prefix_vltime != vltime)
-                       a->flags |= IPV6_AF_NEW;
+                       TAILQ_INSERT_TAIL(&state->addrs, a, next);
+               } else {
+                       a->flags &= ~IPV6_AF_STALE;
+                       if (a->prefix_vltime != vltime)
+                               a->flags |= IPV6_AF_NEW;
+               }
 
                a->prefix_pltime = pltime;
                a->prefix_vltime = vltime;
@@ -1450,10 +1452,6 @@ dhcp6_findpd(struct interface *ifp, const uint8_t *iaid,
                        state->lowpl = a->prefix_pltime;
                if (a->prefix_vltime && a->prefix_vltime > state->expire)
                        state->expire = a->prefix_vltime;
-               if (a->flags & IPV6_AF_STALE)
-                       a->flags &= ~IPV6_AF_STALE;
-               else
-                       TAILQ_INSERT_TAIL(&state->addrs, a, next);
                i++;
        }
        return i;
@@ -1505,6 +1503,25 @@ dhcp6_findia(struct interface *ifp, const uint8_t *d, size_t l,
                        rebind = ntohl(u32);
                        p += sizeof(u32);
                        ol -= sizeof(u32);
+               }
+               if (dhcp6_checkstatusok(ifp, NULL, p, ol) == -1)
+                       continue;
+               if (ifo->ia_type == D6_OPTION_IA_PD) {
+                       if (dhcp6_findpd(ifp, iaid, p, ol) == 0) {
+                               syslog(LOG_WARNING,
+                                   "%s: %s: DHCPv6 REPLY missing Prefix",
+                                   ifp->name, sfrom);
+                               continue;
+                       }
+               } else {
+                       if (dhcp6_findna(ifp, iaid, p, ol) == 0) {
+                               syslog(LOG_WARNING,
+                                   "%s: %s: DHCPv6 REPLY missing IA Address",
+                                   ifp->name, sfrom);
+                               continue;
+                       }
+               }
+               if (ifo->ia_type != D6_OPTION_IA_TA) {
                        if (renew > rebind && rebind > 0) {
                                if (sfrom)
                                    syslog(LOG_WARNING,
@@ -1520,23 +1537,6 @@ dhcp6_findia(struct interface *ifp, const uint8_t *d, size_t l,
                            (rebind < state->rebind || state->rebind == 0))
                                state->rebind = rebind;
                }
-               if (dhcp6_checkstatusok(ifp, NULL, p, ol) == -1)
-                       return -1;
-               if (ifo->ia_type == D6_OPTION_IA_PD) {
-                       if (dhcp6_findpd(ifp, iaid, p, ol) == 0) {
-                               syslog(LOG_ERR,
-                                   "%s: %s: DHCPv6 REPLY missing Prefix",
-                                   ifp->name, sfrom);
-                               return -1;
-                       }
-               } else {
-                       if (dhcp6_findna(ifp, iaid, p, ol) == 0) {
-                               syslog(LOG_ERR,
-                                   "%s: %s: DHCPv6 REPLY missing IA Address",
-                                   ifp->name, sfrom);
-                               return -1;
-                       }
-               }
                i++;
        }
        TAILQ_FOREACH_SAFE(ap, &state->addrs, next, nap) {