]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Change IF_SSIDSIZE to IF_SSIDLEN to be more clear about it.
authorRoy Marples <roy@marples.name>
Thu, 11 Feb 2016 16:06:26 +0000 (16:06 +0000)
committerRoy Marples <roy@marples.name>
Thu, 11 Feb 2016 16:06:26 +0000 (16:06 +0000)
Store an extra char for a NULL terminator solely for debubgging purposes.
A better fix for [be2bbe6e37].

dhcp.h
dhcp6.h
dhcpcd.c
dhcpcd.h
if-bsd.c
if-linux-wext.c
if-linux.c
if.c

diff --git a/dhcp.h b/dhcp.h
index efc97a0c92c4dc40150e9306abc5164e7199e229..241a584ff417a42061673e57a04309c1e5bddcd6 100644 (file)
--- 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 8135d11572f62623acc93f65564c9df4ff09353a..93605be7e449d9fa3ce8c1220d6901f46e32ad5b 100644 (file)
--- 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;
index 6b227bfe35a2536944f6d4258ae2d7c14cc1a152..4e37a681ac205608b6da5c9392d26c0f40eb07cf 100644 (file)
--- 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;
 
index b74dbacb3a0b7d7a6205ca7b10bfcc74a7e9b819..b3f76781180e51afd917da5b0f1c74bda32732c2 100644 (file)
--- 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];
index ed508086c031b0848f2ad0b39f29865389b5327e..06c512740245c433a54b8dc8d9419c5c72b0b040 100644 (file)
--- 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;
 }
 
index 860cba96a15c8995a04befcf406a324865d5b62a..96f7a7f41d6c701e5b5afa76166107ffacd24ed6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2009-2015 Roy Marples <roy@marples.name>
+ * Copyright (c) 2009-2016 Roy Marples <roy@marples.name>
  * 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;
index aad7b6907e741f4991a661588a7fa9cba9d38ea1..0f7143ce809afbf60f5f3146209d6408aeabea68 100644 (file)
@@ -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 49c273a6feae9c83d91c21fb46a4f6e4c2c5b212..1b902479d062d7d27d87924c6baa271c596c9087 100644 (file)
--- 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. */