]> granicus.if.org Git - curl/commitdiff
avoid an overflow if an excessive amount of servers are used
authorDaniel Stenberg <daniel@haxx.se>
Thu, 12 Oct 2006 16:47:50 +0000 (16:47 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 12 Oct 2006 16:47:50 +0000 (16:47 +0000)
ares/ares_getsock.c

index 55f4c9ddae9d2b370be34ce1b6e176cd921cbac0..a6288e986ab9a37ab62708672baeae941a021396 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/* Copyright 2005 by Daniel Stenberg.
+/* Copyright (C) 2005 - 2006, Daniel Stenberg
  *
  * Permission to use, copy, modify, and distribute this software and its
  * documentation for any purpose and without fee is hereby granted, provided
@@ -39,7 +39,9 @@ int ares_getsock(ares_channel channel,
   if (!channel->queries)
     return 0;
 
-  for (i = 0; i < channel->nservers; i++)
+  for (i = 0;
+       (i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
+       i++)
     {
       server = &channel->servers[i];
       if (server->udp_socket != ARES_SOCKET_BAD)
@@ -56,13 +58,12 @@ int ares_getsock(ares_channel channel,
            break;
          socks[sockindex] = server->tcp_socket;
          bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
-         sockindex++;
 
-         if (server->qhead) {
+         if (server->qhead)
            /* then the tcp socket is also writable! */
-           bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex-1);
-         }
+           bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);
 
+         sockindex++;
        }
     }
   return bitmap;