diff --git a/src/dhcp-common.c b/src/dhcp-common.c index e87094de..fd090f05 100644 --- a/src/dhcp-common.c +++ b/src/dhcp-common.c @@ -1013,7 +1013,7 @@ dhcp_set_leasefile(char *leasefile, size_t len, int family, const struct interface *ifp) { char ifname[(sizeof(ifp->name) * 4) + 1]; - char ssid[1 + (IF_SSIDLEN * 4) + 1]; /* - prefix and NUL terminated. */ + char ssid[1 + IF_SSIDSTRLEN]; /* - prefix and escaped SSID. */ if (ifp->name[0] == '\0') { strlcpy(leasefile, ifp->ctx->pidfile, len); diff --git a/src/dhcp.h b/src/dhcp.h index 5dbea7d5..73ac5e9c 100644 --- a/src/dhcp.h +++ b/src/dhcp.h @@ -229,7 +229,7 @@ struct dhcp_state { struct ipv4_addr *addr; uint8_t added; - char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDLEN * 4)]; + char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + IF_SSIDSTRLEN]; struct timespec started; unsigned char *clientid; struct authstate auth; diff --git a/src/dhcp6.h b/src/dhcp6.h index 75e80a0d..01af741c 100644 --- a/src/dhcp6.h +++ b/src/dhcp6.h @@ -212,7 +212,7 @@ struct dhcp6_state { struct ipv6_addrhead addrs; uint32_t lowpl; /* The +3 is for the possible .pd extension for prefix delegation */ - char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) + 3]; + char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + IF_SSIDSTRLEN + 3]; const char *reason; uint16_t lerror; /* Last error received from DHCPv6 reply. */ bool has_no_binding; diff --git a/src/dhcpcd.c b/src/dhcpcd.c index bf277bbc..9cc1bb89 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -628,7 +628,7 @@ int dhcpcd_selectprofile(struct interface *ifp, const char *profile) { struct if_options *ifo; - char pssid[PROFILE_LEN]; + char pssid[IF_SSIDSTRLEN]; if (ifp->ssid_len) { ssize_t r; @@ -717,7 +717,7 @@ dhcpcd_initstate(struct interface *ifp, unsigned long long options) static void dhcpcd_reportssid(struct interface *ifp) { - char pssid[IF_SSIDLEN * 4]; + char pssid[IF_SSIDSTRLEN]; if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid, ifp->ssid_len) == -1) { diff --git a/src/dhcpcd.h b/src/dhcpcd.h index f097c95f..b0f38d40 100644 --- a/src/dhcpcd.h +++ b/src/dhcpcd.h @@ -45,6 +45,8 @@ #define IF_SSIDLEN 32 #define PROFILE_LEN 64 #define SECRET_LEN 64 +/* An escaped SSID needs four characters per-octet, plus terminating NUL */ +#define IF_SSIDSTRLEN ((IF_SSIDLEN * 4) + 1) #define IF_INACTIVE 0 #define IF_ACTIVE 1 diff --git a/src/script.c b/src/script.c index e059472e..2464643f 100644 --- a/src/script.c +++ b/src/script.c @@ -393,7 +393,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, if (efprintf(fp, "ifmtu=%d", if_getmtu(ifp)) == -1) goto eexit; if (ifp->wireless) { - char pssid[IF_SSIDLEN * 4]; + char pssid[IF_SSIDSTRLEN]; if (print_string(pssid, sizeof(pssid), OT_ESCSTRING, ifp->ssid, ifp->ssid_len) != -1) {