From: Vsevolod Stakhov Date: Tue, 6 Mar 2018 08:43:04 +0000 (+0000) Subject: [Minor] Allow to proxy empty files X-Git-Tag: 1.7.0~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d51d49e381e1eb690fdf0583f0b61121f6ad9911;p=thirdparty%2Frspamd.git [Minor] Allow to proxy empty files --- diff --git a/src/libutil/util.c b/src/libutil/util.c index c8de9a6512..d025730ac4 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 a7c20e34b6..53e954a583 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 */