aboutsummaryrefslogtreecommitdiffstats
path: root/lib/librspamdclient.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-06-17 17:24:55 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-06-17 17:24:55 +0400
commitfba45df3a0f7620e128339cb4e4f95eb63ca5d6a (patch)
tree1940929267ed29702c757ab3a016777f28cb34df /lib/librspamdclient.c
parenta47bd1324d38975e283d09027645bdbe06abef4e (diff)
downloadrspamd-fba45df3a0f7620e128339cb4e4f95eb63ca5d6a.tar.gz
rspamd-fba45df3a0f7620e128339cb4e4f95eb63ca5d6a.zip
Handle files with zero lenght properly.
Reported by: Andrej Zverev
Diffstat (limited to 'lib/librspamdclient.c')
-rw-r--r--lib/librspamdclient.c21
1 files changed, 21 insertions, 0 deletions
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) {