In single INSTREAM mode, remove FD from polled set (BB #1410)

Fix testcase, INSTREAM should say UNKNOWN COMMAND in old mode and close conn, sending
anything after it will likely result in a broken pipe.(BB #1407)

git-svn: trunk@4826
0.95
Török Edvin 16 years ago
parent 649a1759a9
commit 4d26118b95
  1. 8
      ChangeLog
  2. 16
      clamd/server-th.c
  3. 1
      unit_tests/check_clamd.c
  4. 2
      unit_tests/test-clamd.conf

@ -1,3 +1,11 @@
Wed Feb 18 21:08:50 EET 2009 (edwin)
------------------------------------
* clamd/server-th.c, unit_tests/check_clamd.c,
unit_tests/test-clamd.conf: In single INSTREAM mode, remove FD from
polled set (BB #1410) Fix testcase, INSTREAM should say UNKNOWN
COMMAND in old mode and close conn, sending anything after it will
likely result in a broken pipe.(BB #1407)
Wed Feb 18 20:35:16 EET 2009 (edwin)
------------------------------------
* libclamav/bignum.h: disable __mode__(TI) code (bb #1409)

@ -121,7 +121,7 @@ static void scanner_thread(void *arg)
logg("$Finished scanthread\n");
if (thrmgr_group_finished(conn->group, virus ? EXIT_OTHER :
errors ? EXIT_ERROR : EXIT_OK)) {
logg("$Scanthread: connection shut down\n");
logg("$Scanthread: connection shut down (FD %d)\n", conn->sd);
/* close connection if we were last in group */
shutdown(conn->sd, 2);
closesocket(conn->sd);
@ -355,6 +355,7 @@ static void *acceptloop_th(void *arg)
continue;
}
if (buf->got_newdata == -1) {
logg("$Acceptloop closed FD: %d\n", buf->fd);
shutdown(buf->fd, 2);
closesocket(buf->fd);
buf->fd = -1;
@ -385,7 +386,6 @@ static void *acceptloop_th(void *arg)
/* listen only socket */
new_sd = accept(fds->buf[i].fd, NULL, NULL);
if (new_sd >= 0) {
int ret, flags;
@ -399,8 +399,10 @@ static void *acceptloop_th(void *arg)
} else {
logg("^Can't get socket flags, errno %d\n", errno);
}
#else
logg("^Nonblocking sockets not available!\n");
#endif
logg("$Got new connection, FD %d\n", new_sd);
pthread_mutex_lock(&recv_fds->buf_mutex);
ret = fds_add(recv_fds, new_sd, 0, commandtimeout);
pthread_mutex_unlock(&recv_fds->buf_mutex);
@ -443,6 +445,7 @@ static void *acceptloop_th(void *arg)
for (i=0;i < fds->nfds; i++) {
if (fds->buf[i].fd == -1)
continue;
logg("$Shutdown: closed fd %d\n", fds->buf[i].fd);
shutdown(fds->buf[i].fd, 2);
closesocket(fds->buf[i].fd);
}
@ -956,7 +959,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
}
if (error || !conn.group || rc) {
if (rc && thrmgr_group_finished(conn.group, EXIT_OK)) {
logg("$Receive thread: closing conn, group finished\n");
logg("$Receive thread: closing conn (FD %d), group finished\n", conn.sd);
/* if there are no more active jobs */
shutdown(conn.sd, 2);
closesocket(conn.sd);
@ -1056,6 +1059,8 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
conn.term = buf->term;
buf->dumpfd = -1;
buf->mode = buf->group ? MODE_COMMAND : MODE_WAITREPLY;
if (buf->mode == MODE_WAITREPLY)
buf->fd = -1;
logg("$Chunks complete\n");
buf->dumpname = NULL;
if ((rc = execute_or_dispatch_command(&conn, COMMAND_INSTREAMSCAN, NULL)) < 0) {
@ -1121,7 +1126,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
}
thrmgr_group_terminate(buf->group);
if (thrmgr_group_finished(buf->group, EXIT_ERROR)) {
logg("$Shutting down socket after error\n");
logg("$Shutting down socket after error (FD %d)\n", buf->fd);
shutdown(buf->fd, 2);
closesocket(buf->fd);
} else
@ -1141,6 +1146,7 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi
continue;
thrmgr_group_terminate(fds->buf[i].group);
if (thrmgr_group_finished(fds->buf[i].group, EXIT_ERROR)) {
logg("$Shutdown closed fd %d\n", fds->buf[i].fd);
shutdown(fds->buf[i].fd, 2);
closesocket(fds->buf[i].fd);
fds->buf[i].fd = -1;

@ -256,6 +256,7 @@ START_TEST (test_compat_commands)
if (!test->support_old) {
snprintf(nreply, sizeof(nreply), "UNKNOWN COMMAND\n");
test->extra = NULL;
} else {
snprintf(nreply, sizeof(nreply), "%s\n", test->reply);
}

@ -1,5 +1,5 @@
# script will fill in CWD and X
LogFile CWD/clamd-testX.log
LogFile CWD/../clamd-testX.log
LogFileMaxSize 0
LogTime yes
Debug yes

Loading…
Cancel
Save