summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-10-12 16:47:50 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-10-12 16:47:50 +0000
commit04cb824483f4394b7717a1354fe218de6dbb4d5c (patch)
tree43845a3eed2b137d1da1723678dfe3cf3862b0dd
parent298541c56c352fedc14ba2dcf71549adfcc70b7d (diff)
downloadc-ares-04cb824483f4394b7717a1354fe218de6dbb4d5c.tar.gz
c-ares-04cb824483f4394b7717a1354fe218de6dbb4d5c.tar.bz2
c-ares-04cb824483f4394b7717a1354fe218de6dbb4d5c.zip
avoid an overflow if an excessive amount of servers are used
-rw-r--r--ares_getsock.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/ares_getsock.c b/ares_getsock.c
index 55f4c9d..a6288e9 100644
--- a/ares_getsock.c
+++ b/ares_getsock.c
@@ -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;