aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-06-05 20:08:44 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-06-05 20:08:44 +0400
commitee97d0365907a159901c3cb47f9e4a2f5bdd61d6 (patch)
tree52f18387c204a59c66096e96ee7f8764a3f53e2a /lib
parent20c329815f2855d7c1356c3bbe26bddca20ac281 (diff)
downloadrspamd-ee97d0365907a159901c3cb47f9e4a2f5bdd61d6.tar.gz
rspamd-ee97d0365907a159901c3cb47f9e4a2f5bdd61d6.zip
Fix rspamdclient bug while reading controller's greeting.
Diffstat (limited to 'lib')
-rw-r--r--lib/client/librspamdclient.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/lib/client/librspamdclient.c b/lib/client/librspamdclient.c
index 2fbc2692d..37b6aa847 100644
--- a/lib/client/librspamdclient.c
+++ b/lib/client/librspamdclient.c
@@ -1185,34 +1185,43 @@ rspamd_controller_auth (struct rspamd_connection *c, const gchar *password, GErr
static gboolean
rspamd_read_controller_greeting (struct rspamd_connection *c, GError **err)
{
- gchar inbuf[BUFSIZ];
- gint r;
+ gchar inbuf[BUFSIZ], *pos;
+ gint r, got_greeting = FALSE;
static const gchar greeting_str[] = "Rspamd";
- if ((r = poll_sync_socket (c->socket, c->client->read_timeout, POLL_IN)) <= 0) {
- if (*err == NULL) {
- if (r == 0) {
- errno = ETIMEDOUT;
+ pos = inbuf;
+
+ while (pos - inbuf < (gint)sizeof (inbuf)) {
+ if ((r = poll_sync_socket (c->socket, c->client->read_timeout, POLL_IN)) <= 0) {
+ if (*err == NULL) {
+ if (r == 0) {
+ errno = ETIMEDOUT;
+ }
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Cannot read reply from controller %s: %s",
+ c->server->name, strerror (errno));
}
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Cannot read reply from controller %s: %s",
- c->server->name, strerror (errno));
+ upstream_fail (&c->server->up, c->connection_time);
+ return FALSE;
}
- upstream_fail (&c->server->up, c->connection_time);
- return FALSE;
- }
- if ((r = read (c->socket, inbuf, sizeof (inbuf))) > 0) {
- if (r >= (gint)sizeof (greeting_str) - 1 &&
- memcmp (inbuf, greeting_str, sizeof (greeting_str) - 1) == 0) {
- return TRUE;
+ if ((r = read (c->socket, pos, sizeof (inbuf) - (pos - inbuf))) > 0) {
+ if (r >= (gint)sizeof (greeting_str) - 1 &&
+ memcmp (inbuf, greeting_str, sizeof (greeting_str) - 1) == 0) {
+ got_greeting = TRUE;
+ }
}
- }
- else {
- if (*err == NULL) {
- *err = g_error_new (G_RSPAMD_ERROR, errno, "Cannot read reply from controller %s: %s",
- c->server->name, strerror (errno));
+ else {
+ if (*err == NULL) {
+ *err = g_error_new (G_RSPAMD_ERROR, errno, "Cannot read reply from controller %s: %s",
+ c->server->name, strerror (errno));
+ }
+ upstream_fail (&c->server->up, c->connection_time);
+ return FALSE;
+ }
+ pos += r;
+ if (got_greeting && *(pos - 1) == '\n') {
+ /* Got the complete greeting */
+ return TRUE;
}
- upstream_fail (&c->server->up, c->connection_time);
- return FALSE;
}
return FALSE;