Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13713
Modified Files:
Tag: Nov2009
merovingian_controlrunner.c
Log Message:
protect ourself from clients that connect but never tell us what they want
U merovingian_controlrunner.c
Index: merovingian_controlrunner.c
===================================================================
RCS file:
/cvsroot/monetdb/sql/src/backends/monet5/merovingian/merovingian_controlrunner.c,v
retrieving revision 1.26.2.3
retrieving revision 1.26.2.4
diff -u -d -r1.26.2.3 -r1.26.2.4
--- merovingian_controlrunner.c 1 Oct 2009 09:22:06 -0000 1.26.2.3
+++ merovingian_controlrunner.c 1 Oct 2009 19:17:52 -0000 1.26.2.4
@@ -61,6 +61,28 @@
GDKfree(props);
}
+inline static int
+recvWithTimeout(int msgsock, char *buf, size_t buflen)
+{
+ fd_set fds;
+ struct timeval tv;
+ int retval;
+
+ FD_ZERO(&fds);
+ FD_SET(msgsock, &fds);
+
+ /* Wait up to 1 second. If a client doesn't make this, it's too slow */
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ retval = select(msgsock + 1, &fds, NULL, NULL, &tv);
+ if (retval == 0) {
+ /* nothing interesting has happened */
+ return(-2);
+ }
+
+ return(recv(msgsock, buf, buflen, 0));
+}
+
static void
controlRunner(void *d)
{
@@ -175,7 +197,7 @@
len = snprintf(buf2, sizeof(buf2),
"merovingian:1:%s:\n", p);
send(msgsock, buf2, len, 0);
- if ((pos = recv(msgsock, buf2, sizeof(buf2), 0)) == 0) {
+ if ((pos = recvWithTimeout(msgsock, buf2,
sizeof(buf2))) == 0) {
close(msgsock);
continue;
} else if (pos == -1) {
@@ -183,6 +205,11 @@
"channel: %s\n", origin,
strerror(errno));
close(msgsock);
continue;
+ } else if (pos == -2) {
+ Mfprintf(_mero_ctlerr, "%s: time-out reading
from control "
+ "channel, disconnecting
client\n", origin);
+ close(msgsock);
+ continue;
}
buf2[pos - 1] = '\0';
pos = 0;
@@ -203,7 +230,7 @@
while (_mero_keep_listening) {
if (pos == 0) {
- if ((pos = recv(msgsock, buf, sizeof(buf), 0))
== 0) {
+ if ((pos = recvWithTimeout(msgsock, buf,
sizeof(buf))) == 0) {
/* EOF */
break;
} else if (pos == -1) {
@@ -216,6 +243,11 @@
Mfprintf(_mero_ctlerr, "%s: error
reading from control "
"channel: %s\n",
origin, strerror(errno));
break;
+ } else if (pos == -2) {
+ Mfprintf(_mero_ctlerr, "%s: time-out
reading from "
+ "control channel,
disconnecting client\n", origin);
+ close(msgsock);
+ break;
} else {
buf[pos] = '\0';
pos = 0;
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins