--- ./dhcp6.c +++ ./dhcp6.c @@ -111,11 +111,12 @@ "Success", "Unspecified Failure", "No Addresses Available", "No Binding", "Not On Link", - "Use Multicast" + "Use Multicast", + "No Prefix Available" }; struct dhcp6_ia_addr { struct in6_addr addr; uint32_t pltime; @@ -1660,11 +1661,12 @@ dhcp6_checkstatusok(const struct interface *ifp, const struct dhcp6_message *m, const uint8_t *p, size_t len) { 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); else o = dhcp6_getmoption(D6_OPTION_STATUS_CODE, m, len); @@ -1686,28 +1688,29 @@ return 1; 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); + 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; + } - status = malloc(len + 1); - if (status == NULL) { - logger(ifp->ctx, LOG_ERR, "%s: %m", __func__); - return -1; - } - 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; } const struct ipv6_addr * dhcp6_iffindaddr(const struct interface *ifp, const struct in6_addr *addr,