From fba45df3a0f7620e128339cb4e4f95eb63ca5d6a Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 17 Jun 2011 17:24:55 +0400 Subject: [PATCH] Handle files with zero lenght properly. Reported by: Andrej Zverev --- lib/librspamdclient.c | 21 +++++++++++++++++++++ src/client/rspamc.c | 1 + 2 files changed, 22 insertions(+) diff --git a/lib/librspamdclient.c b/lib/librspamdclient.c index 92c513cdc..39adf0f18 100644 --- a/lib/librspamdclient.c +++ b/lib/librspamdclient.c @@ -1243,6 +1243,7 @@ rspamd_scan_memory (const guchar *message, gsize length, GHashTable *headers, GE struct rspamd_result *res = NULL; g_assert (client != NULL); + g_assert (length > 0); /* Connect to server */ c = rspamd_connect_random_server (FALSE, err); @@ -1328,6 +1329,12 @@ rspamd_scan_fd (int fd, GHashTable *headers, GError **err) } return NULL; } + if (st.st_size == 0) { + if (*err == NULL) { + *err = g_error_new (G_RSPAMD_ERROR, -1, "File has zero length"); + } + return NULL; + } /* Set socket blocking for writing */ make_socket_blocking (c->socket); /* Send command */ @@ -1366,6 +1373,7 @@ rspamd_learn_memory (const guchar *message, gsize length, const gchar *symbol, c static const gchar ok_str[] = "learn ok"; g_assert (client != NULL); + g_assert (length > 0); /* Connect to server */ c = rspamd_connect_random_server (TRUE, err); @@ -1477,6 +1485,12 @@ rspamd_learn_fd (int fd, const gchar *symbol, const gchar *password, GError **er } return FALSE; } + if (st.st_size == 0) { + if (*err == NULL) { + *err = g_error_new (G_RSPAMD_ERROR, -1, "File has zero length"); + } + return FALSE; + } r = sizeof ("learn %s %uz\r\n") + strlen (symbol) + sizeof ("4294967296"); outbuf = g_malloc (r); r = snprintf (outbuf, r, "learn %s %lu\r\n", symbol, (unsigned long)st.st_size); @@ -1513,6 +1527,7 @@ rspamd_fuzzy_memory (const guchar *message, gsize length, const gchar *password, static const gchar ok_str[] = "OK"; g_assert (client != NULL); + g_assert (length > 0); /* Connect to server */ c = rspamd_connect_random_server (TRUE, err); @@ -1628,6 +1643,12 @@ rspamd_fuzzy_fd (int fd, const gchar *password, gint weight, gint flag, gboolean } return FALSE; } + if (st.st_size == 0) { + if (*err == NULL) { + *err = g_error_new (G_RSPAMD_ERROR, -1, "File has zero length"); + } + return FALSE; + } r = sizeof ("fuzzy_add %uz %d %d\r\n") + sizeof ("4294967296") * 3; outbuf = g_malloc (r); if (delete) { diff --git a/src/client/rspamc.c b/src/client/rspamc.c index f5561cdab..80798da05 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -635,6 +635,7 @@ main (gint argc, gchar **argv, gchar **env) } } else { + add_rspamd_server (FALSE); scan_rspamd_file (argv[1]); } } -- 2.39.5