]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
If dhcpcd does not know the DHCPv6 status code, report it as an unknown
authorRoy Marples <roy@marples.name>
Wed, 30 Sep 2015 10:08:29 +0000 (10:08 +0000)
committerRoy Marples <roy@marples.name>
Wed, 30 Sep 2015 10:08:29 +0000 (10:08 +0000)
code instead of a blank string.

dhcp6.c

diff --git a/dhcp6.c b/dhcp6.c
index c326c7693af0b32188340dda604ba83b35c026ea..48883f8f6d064ee73a89623f43ae160fccced9fe 100644 (file)
--- a/dhcp6.c
+++ b/dhcp6.c
@@ -1663,7 +1663,8 @@ dhcp6_checkstatusok(const struct interface *ifp,
 {
        const struct dhcp6_option *o;
        uint16_t code;
-       char *status;
+       char buf[32], *sbuf;
+       const char *status;
 
        if (p)
                o = dhcp6_findoption(D6_OPTION_STATUS_CODE, p, len);
@@ -1689,24 +1690,25 @@ dhcp6_checkstatusok(const struct interface *ifp,
        len -= sizeof(code);
 
        if (len == 0) {
-               if (code < sizeof(dhcp6_statuses) / sizeof(char *)) {
-                       p = (const uint8_t *)dhcp6_statuses[code];
-                       len = strlen((const char *)p);
-               } else
-                       p = NULL;
-       } else
-               p += sizeof(code);
-
-       status = malloc(len + 1);
-       if (status == NULL) {
-               logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
-               return -1;
+               sbuf = NULL;
+               if (code < sizeof(dhcp6_statuses) / sizeof(char *))
+                       status = dhcp6_statuses[code];
+               else {
+                       snprintf(buf, sizeof(buf), "Unknown Status (%d)", code);
+                       status = buf;
+               }
+       } else {
+               if ((sbuf = malloc(len + 1)) == NULL) {
+                       logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
+                       return -1;
+               }
+               memcpy(sbuf, p + sizeof(code), len);
+               sbuf[len] = '\0';
+               status = sbuf;
        }
-       if (p)
-               memcpy(status, p, len);
-       status[len] = '\0';
+
        logger(ifp->ctx, LOG_ERR, "%s: DHCPv6 REPLY: %s", ifp->name, status);
-       free(status);
+       free(sbuf);
        return -1;
 }