]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
loop: Use size_t for eloop.count
authorJouni Malinen <j@w1.fi>
Sun, 22 Mar 2020 16:35:45 +0000 (18:35 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 22 Mar 2020 16:50:04 +0000 (18:50 +0200)
This is more consistent with the other eloop registrations and avoids a
theoretical integer overflow with 16-bit int should more than 32767
sockets/signals/events be registered.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/utils/eloop.c

index b4e7f9e71ff44165f149acf886dfba69e962908c..b353ab0e467fa8637820c5a5c5065de68daa15c7 100644 (file)
@@ -77,10 +77,10 @@ struct eloop_sock_table {
 struct eloop_data {
        int max_sock;
 
-       int count; /* sum of all table counts */
+       size_t count; /* sum of all table counts */
 #ifdef CONFIG_ELOOP_POLL
-       int max_pollfd_map; /* number of pollfds_map currently allocated */
-       int max_poll_fds; /* number of pollfds currently allocated */
+       size_t max_pollfd_map; /* number of pollfds_map currently allocated */
+       size_t max_poll_fds; /* number of pollfds currently allocated */
        struct pollfd *pollfds;
        struct pollfd **pollfds_map;
 #endif /* CONFIG_ELOOP_POLL */
@@ -90,12 +90,12 @@ struct eloop_data {
 #endif /* CONFIG_ELOOP_EPOLL || CONFIG_ELOOP_KQUEUE */
 #ifdef CONFIG_ELOOP_EPOLL
        int epollfd;
-       int epoll_max_event_num;
+       size_t epoll_max_event_num;
        struct epoll_event *epoll_events;
 #endif /* CONFIG_ELOOP_EPOLL */
 #ifdef CONFIG_ELOOP_KQUEUE
        int kqueuefd;
-       int kqueue_nevents;
+       size_t kqueue_nevents;
        struct kevent *kqueue_events;
 #endif /* CONFIG_ELOOP_KQUEUE */
        struct eloop_sock_table readers;
@@ -268,7 +268,7 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
 #endif /* CONFIG_ELOOP_EPOLL */
 #if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
        struct eloop_sock *temp_table;
-       int next;
+       size_t next;
 #endif /* CONFIG_ELOOP_EPOLL || CONFIG_ELOOP_KQUEUE */
        struct eloop_sock *tmp;
        int new_max_sock;
@@ -282,7 +282,7 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
                return -1;
 
 #ifdef CONFIG_ELOOP_POLL
-       if (new_max_sock >= eloop.max_pollfd_map) {
+       if ((size_t) new_max_sock >= eloop.max_pollfd_map) {
                struct pollfd **nmap;
                nmap = os_realloc_array(eloop.pollfds_map, new_max_sock + 50,
                                        sizeof(struct pollfd *));
@@ -295,7 +295,8 @@ static int eloop_sock_table_add_sock(struct eloop_sock_table *table,
 
        if (eloop.count + 1 > eloop.max_poll_fds) {
                struct pollfd *n;
-               int nmax = eloop.count + 1 + 50;
+               size_t nmax = eloop.count + 1 + 50;
+
                n = os_realloc_array(eloop.pollfds, nmax,
                                     sizeof(struct pollfd));
                if (n == NULL)