From d51d49e381e1eb690fdf0583f0b61121f6ad9911 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 6 Mar 2018 08:43:04 +0000 Subject: [PATCH] [Minor] Allow to proxy empty files --- src/libutil/util.c | 10 +++++++++- src/rspamd_proxy.c | 16 +++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/libutil/util.c b/src/libutil/util.c index c8de9a651..d025730ac 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -2483,8 +2483,16 @@ rspamd_file_xmap (const char *fname, guint mode, gsize *size, return NULL; } - if (fstat (fd, &sb) == -1 || !S_ISREG (sb.st_mode) || sb.st_size == 0) { + if (fstat (fd, &sb) == -1 || !S_ISREG (sb.st_mode)) { close (fd); + *size = (gsize)-1; + + return NULL; + } + + if (sb.st_size == 0) { + close (fd); + *size = (gsize)0; return NULL; } diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index a7c20e34b..53e954a58 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -1193,9 +1193,12 @@ proxy_check_file (struct rspamd_http_message *msg, TRUE); if (session->map == NULL) { - msg_err_session ("cannot map %s: %s", file_str, strerror (errno)); + if (session->map_len != 0) { + msg_err_session ("cannot map %s: %s", file_str, + strerror (errno)); - return FALSE; + return FALSE; + } } /* Remove header after processing */ rspamd_http_message_remove_header (msg, "File"); @@ -1222,10 +1225,13 @@ proxy_check_file (struct rspamd_http_message *msg, &session->map_len, TRUE); if (session->map == NULL) { - msg_err_session ("cannot map %s: %s", file_str, strerror (errno)); - g_hash_table_unref (query_args); + if (session->map_len != 0) { + msg_err_session ("cannot map %s: %s", file_str, + strerror (errno)); + g_hash_table_unref (query_args); - return FALSE; + return FALSE; + } } /* We need to create a new URL with file attribute removed */ -- 2.39.5