Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/wpa/dist/src/drivers wpa: Fix the maximum size ...



details:   https://anonhg.NetBSD.org/src/rev/0a93bc7fe445
branches:  trunk
changeset: 968821:0a93bc7fe445
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Jan 29 11:57:36 2020 +0000

description:
wpa: Fix the maximum size of a route(4) msg to 2048

This mirrors other programs which parse route(4) messages and will
match upstream.

diffstat:

 external/bsd/wpa/dist/src/drivers/driver_bsd.c |  52 +------------------------
 1 files changed, 3 insertions(+), 49 deletions(-)

diffs (98 lines):

diff -r 39c224c5fc76 -r 0a93bc7fe445 external/bsd/wpa/dist/src/drivers/driver_bsd.c
--- a/external/bsd/wpa/dist/src/drivers/driver_bsd.c    Wed Jan 29 11:46:47 2020 +0000
+++ b/external/bsd/wpa/dist/src/drivers/driver_bsd.c    Wed Jan 29 11:57:36 2020 +0000
@@ -51,7 +51,6 @@
        void            *ctx;
        int             sock;                   /* socket for 802.11 ioctls */
        int             route;                  /* routing socket for events */
-       struct iovec    event_iov[1];
        struct dl_list  ifaces;                 /* list of interfaces */
 };
 
@@ -75,50 +74,6 @@
 
 /* Generic functions for hostapd and wpa_supplicant */
 
-#define IOVEC_BUFSIZ           256
-ssize_t
-recvmsg_realloc(int fd, struct msghdr *msg, int flags)
-{
-       struct iovec *iov;
-       ssize_t slen;
-       size_t len;
-       void *n;
-
-       /* Assume we are reallocing the last iovec. */
-       iov = &msg->msg_iov[msg->msg_iovlen - 1];
-
-       for (;;) {
-               /* Passing MSG_TRUNC should return the actual size needed. */
-               slen = recvmsg(fd, msg, flags | MSG_PEEK | MSG_TRUNC);
-               if (slen == -1)
-                       return -1;
-               if (!(msg->msg_flags & MSG_TRUNC))
-                       break;
-
-               len = (size_t)slen;
-
-               /* Some kernels return the size of the receive buffer
-                * on truncation, not the actual size needed.
-                * So grow the buffer and try again. */
-               if (iov->iov_len == len)
-                       len = roundup(len + 1, IOVEC_BUFSIZ);
-               else if (iov->iov_len > len)
-                       break;
-               if ((n = realloc(iov->iov_base, len)) == NULL)
-                       return -1;
-               iov->iov_base = n;
-               iov->iov_len = len;
-       }
-
-       slen = recvmsg(fd, msg, flags);
-       if (slen != -1 && msg->msg_flags & MSG_TRUNC) {
-               /* This should not be possible ... */
-               errno = ENOBUFS;
-               return -1;
-       }
-       return slen;
-}
-
 static struct bsd_driver_data *
 bsd_get_drvindex(void *priv, unsigned int ifindex)
 {
@@ -662,6 +617,7 @@
 static void
 bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
 {
+       char event_buf[2048]; /* max size of a single route(4) msg */
        struct bsd_driver_global *global = sock_ctx;
        struct bsd_driver_data *drv;
        struct if_announcemsghdr *ifan;
@@ -672,9 +628,8 @@
        struct ieee80211_leave_event *leave;
        struct ieee80211_join_event *join;
        int n;
-       struct msghdr msg = { .msg_iov = global->event_iov, .msg_iovlen = 1};
 
-       n = recvmsg_realloc(sock, &msg, 0);
+       n = read(sock, event_buf, sizeof(event_buf));
        if (n < 0) {
                if (errno != EINTR && errno != EAGAIN)
                        wpa_printf(MSG_ERROR, "%s read() failed: %s",
@@ -682,7 +637,7 @@
                return;
        }
 
-       rtm = (struct rt_msghdr *) global->event_iov[0].iov_base;
+       rtm = (struct rt_msghdr *) event_buf;
        if (rtm->rtm_version != RTM_VERSION) {
                wpa_printf(MSG_DEBUG, "Invalid routing message version=%d",
                           rtm->rtm_version);
@@ -1639,7 +1594,6 @@
        eloop_unregister_read_sock(global->route);
        (void) close(global->route);
        (void) close(global->sock);
-       free(global->event_iov[0].iov_base);
        os_free(global);
 }
 



Home | Main Index | Thread Index | Old Index