From: Roy Marples Date: Thu, 11 Feb 2016 16:06:26 +0000 (+0000) Subject: Change IF_SSIDSIZE to IF_SSIDLEN to be more clear about it. X-Git-Tag: v6.10.2~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5afdbdb72e50ae5f915360f812a44f0c0b76df6;p=thirdparty%2Fdhcpcd.git Change IF_SSIDSIZE to IF_SSIDLEN to be more clear about it. Store an extra char for a NULL terminator solely for debubgging purposes. A better fix for [be2bbe6e37]. --- diff --git a/dhcp.h b/dhcp.h index efc97a0c..241a584f 100644 --- a/dhcp.h +++ b/dhcp.h @@ -218,7 +218,7 @@ struct dhcp_state { struct in_addr dst; uint8_t added; - char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDSIZE * 4)]; + char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDLEN * 4)]; struct timespec started; unsigned char *clientid; struct authstate auth; diff --git a/dhcp6.h b/dhcp6.h index 8135d115..93605be7 100644 --- a/dhcp6.h +++ b/dhcp6.h @@ -199,7 +199,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_SSIDSIZE * 4) +3]; + char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE + (IF_SSIDLEN * 4) +3]; const char *reason; struct authstate auth; diff --git a/dhcpcd.c b/dhcpcd.c index 6b227bfe..4e37a681 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -790,7 +790,7 @@ dhcpcd_handlecarrier(struct dhcpcd_ctx *ctx, int carrier, unsigned int flags, dhcpcd_handleinterface(ctx, 0, ifp->name); #endif if (ifp->wireless) { - uint8_t ossid[IF_SSIDSIZE]; + uint8_t ossid[IF_SSIDLEN]; #ifdef NOCARRIER_PRESERVE_IP size_t olen; diff --git a/dhcpcd.h b/dhcpcd.h index b74dbacb..b3f76781 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -41,7 +41,7 @@ #include "if-options.h" #define HWADDR_LEN 20 -#define IF_SSIDSIZE 33 +#define IF_SSIDLEN 32 #define PROFILE_LEN 64 #define SECRET_LEN 64 @@ -87,7 +87,7 @@ struct interface { unsigned int metric; int carrier; int wireless; - uint8_t ssid[IF_SSIDSIZE]; + uint8_t ssid[IF_SSIDLEN + 1]; /* NULL terminated */ unsigned int ssid_len; char profile[PROFILE_LEN]; diff --git a/if-bsd.c b/if-bsd.c index ed508086..06c51274 100644 --- a/if-bsd.c +++ b/if-bsd.c @@ -149,7 +149,7 @@ if_getssid1(int s, const char *ifname, uint8_t *ssid) struct ieee80211_nwid nwid; #elif defined(IEEE80211_IOC_SSID) struct ieee80211req ireq; - char nwid[IEEE80211_NWID_LEN + 1]; + char nwid[IEEE80211_NWID_LEN]; #endif #if defined(SIOCG80211NWID) /* NetBSD */ @@ -160,13 +160,11 @@ if_getssid1(int s, const char *ifname, uint8_t *ssid) if (ioctl(s, SIOCG80211NWID, &ifr) == 0) { if (ssid == NULL) retval = nwid.i_len; - else if (nwid.i_len > IF_SSIDSIZE) { + else if (nwid.i_len > IF_SSIDLEN) errno = ENOBUFS; - retval = -1; - } else { + else { retval = nwid.i_len; memcpy(ssid, nwid.i_nwid, nwid.i_len); - ssid[nwid.i_len] = '\0'; } } #elif defined(IEEE80211_IOC_SSID) /* FreeBSD */ @@ -179,15 +177,15 @@ if_getssid1(int s, const char *ifname, uint8_t *ssid) if (ioctl(s, SIOCG80211, &ireq) == 0) { if (ssid == NULL) retval = ireq.i_len; - else if (ireq.i_len > IF_SSIDSIZE - 1) { + else if (ireq.i_len > IF_SSIDLEN) errno = ENOBUFS; - retval = -1; - } else { + else { retval = ireq.i_len; memcpy(ssid, nwid, ireq.i_len); - ssid[ireq.i_len] = '\0'; } } +#else + errno = ENOSYS; #endif return retval; @@ -201,6 +199,9 @@ if_getssid(struct interface *ifp) r = if_getssid1(ifp->ctx->pf_inet_fd, ifp->name, ifp->ssid); if (r != -1) ifp->ssid_len = (unsigned int)r; + else + ifp->ssid_len = 0; + ifp->ssid[ifp->ssid_len] = '\0'; return r; } diff --git a/if-linux-wext.c b/if-linux-wext.c index 860cba96..96f7a7f4 100644 --- a/if-linux-wext.c +++ b/if-linux-wext.c @@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright (c) 2009-2015 Roy Marples + * Copyright (c) 2009-2016 Roy Marples * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -58,7 +58,7 @@ /* We can't include if.h or dhcpcd.h because * they would pull in net/if.h, which defeats the purpose of this hack. */ -#define IF_SSIDSIZE 33 +#define IF_SSIDLEN 32 int if_getssid_wext(const char *ifname, uint8_t *ssid); int @@ -73,12 +73,11 @@ if_getssid_wext(const char *ifname, uint8_t *ssid) memset(&iwr, 0, sizeof(iwr)); strlcpy(iwr.ifr_name, ifname, sizeof(iwr.ifr_name)); iwr.u.essid.pointer = ssid; - iwr.u.essid.length = IF_SSIDSIZE - 1; + iwr.u.essid.length = IF_SSIDLEN; - if (ioctl(s, SIOCGIWESSID, &iwr) == 0) { + if (ioctl(s, SIOCGIWESSID, &iwr) == 0) retval = iwr.u.essid.length; - ssid[retval] = '\0'; - } else + else retval = -1; close(s); return retval; diff --git a/if-linux.c b/if-linux.c index aad7b690..0f7143ce 100644 --- a/if-linux.c +++ b/if-linux.c @@ -1106,7 +1106,7 @@ _if_getssid(__unused struct dhcpcd_ctx *ctx, struct interface *ifp, } ifp->ssid_len = NLA_LEN(tb[NL80211_ATTR_SSID]); - if (ifp->ssid_len > sizeof(ifp->ssid) - 1) { + if (ifp->ssid_len > IF_SSIDLEN) { errno = ENOBUFS; ifp->ssid_len = 0; return -1; @@ -1114,7 +1114,6 @@ _if_getssid(__unused struct dhcpcd_ctx *ctx, struct interface *ifp, memcpy(ifp->ssid, NLA_DATA(tb[NL80211_ATTR_SSID]), ifp->ssid_len); out: - ifp->ssid[ifp->ssid_len] = '\0'; return (int)ifp->ssid_len; } @@ -1148,10 +1147,16 @@ if_getssid(struct interface *ifp) r = if_getssid_wext(ifp->name, ifp->ssid); if (r != -1) ifp->ssid_len = (unsigned int)r; + else { #ifdef HAVE_NL80211_H - else if (r == -1) r = if_getssid_nl80211(ifp); + if (r == -1) + ifp->ssid_len = 0; +#else + ifp->ssid_len = 0; #endif + } + ifp->ssid[ifp->ssid_len] = '\0'; return r; } diff --git a/if.c b/if.c index 49c273a6..1b902479 100644 --- a/if.c +++ b/if.c @@ -525,6 +525,7 @@ if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv) strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); if (ioctl(ctx->pf_inet_fd, SIOCGIFPRIORITY, &ifr) == 0) ifp->metric = (unsigned int)ifr.ifr_metric; + if_getssid(ifp); #else /* We reserve the 100 range for virtual interfaces, if and when * we can work them out. */