]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Allow quoted filenames in scan input.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Aug 2015 21:38:03 +0000 (22:38 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 5 Aug 2015 21:38:03 +0000 (22:38 +0100)
src/libserver/protocol.c
src/libserver/task.c
test/functional/cases/scan_file.sh

index 1fedbbb46ea6796edc384cccdd6cd0d4e9653bb4..a87d8751e5e0062ab835cdff9c0ffd71503f95cc 100644 (file)
@@ -262,7 +262,6 @@ rspamd_protocol_handle_url (struct rspamd_task *task,
                                        (p - task->msg.start)) == 0 ||
                                memcmp (task->msg.start, "path",
                                        (p - task->msg.start)) == 0)) {
-                               task->flags |= RSPAMD_TASK_FLAG_FILE;
                                task->msg.start = p + 1;
                                task->msg.len -= (p - task->msg.start) + 1;
                                task->flags |= RSPAMD_TASK_FLAG_FILE;
index ebd78b4a9ecfcb406a106a48b5085ee79bfade89..c2d751dfe5018ec200e34e33bf2b677f98614489 100644 (file)
@@ -259,8 +259,8 @@ rspamd_task_load_message (struct rspamd_task *task,
        guint control_len, r;
        struct ucl_parser *parser;
        ucl_object_t *control_obj;
-       gchar filepath[PATH_MAX];
-       gint fd;
+       gchar filepath[PATH_MAX], *fp;
+       gint fd, flen;
        gpointer map;
        struct stat st;
 
@@ -275,18 +275,28 @@ rspamd_task_load_message (struct rspamd_task *task,
                                MIN (sizeof (filepath), task->msg.len + 1));
 
                rspamd_unescape_uri (filepath, filepath, r + 1);
+               flen = strlen (filepath);
 
-               if (access (filepath, R_OK) == -1 || stat (filepath, &st) == -1) {
+               if (filepath[0] == '"' && flen > 2) {
+                       /* We need to unquote filepath */
+                       fp = &filepath[1];
+                       fp[flen - 2] = '\0';
+               }
+               else {
+                       fp = &filepath[0];
+               }
+
+               if (access (fp, R_OK) == -1 || stat (fp, &st) == -1) {
                        g_set_error (&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
-                                       "Invalid file (%s): %s", filepath, strerror (errno));
+                                       "Invalid file (%s): %s", fp, strerror (errno));
                        return FALSE;
                }
 
-               fd = open (filepath, O_RDONLY);
+               fd = open (fp, O_RDONLY);
 
                if (fd == -1) {
                        g_set_error (&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
-                                       "Cannot open file (%s): %s", filepath, strerror (errno));
+                                       "Cannot open file (%s): %s", fp, strerror (errno));
                        return FALSE;
                }
 
@@ -296,7 +306,7 @@ rspamd_task_load_message (struct rspamd_task *task,
                if (map == MAP_FAILED) {
                        close (fd);
                        g_set_error (&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
-                                       "Cannot mmap file (%s): %s", filepath, strerror (errno));
+                                       "Cannot mmap file (%s): %s", fp, strerror (errno));
                        return FALSE;
                }
 
index 89a8d176c5134a599f73bb97820479810da0805f..1a06067858e99d3104e612abc109db2a8b29a712 100644 (file)
@@ -13,10 +13,17 @@ check_output 'GTUBE'
 run perl "$TEST_DIRNAME/cases/scan_file.pl" "path=$TEST_DIRNAME/messages/gtube.eml"
 check_output 'GTUBE'
 
+run perl "$TEST_DIRNAME/cases/scan_file.pl" "path=\"$TEST_DIRNAME/messages/gtube.eml\""
+check_output 'GTUBE'
+
 # Hex encode every character
 _hex_name=`printf "$TEST_DIRNAME/messages/gtube.eml" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g'`
 run perl "$TEST_DIRNAME/cases/scan_file.pl" "${_hex_name}"
 check_output 'GTUBE'
 
 run perl "$TEST_DIRNAME/cases/scan_file.pl" "file=${_hex_name}"
-check_output 'GTUBE'
\ No newline at end of file
+check_output 'GTUBE'
+
+_hex_name=`printf "\"$TEST_DIRNAME/messages/gtube.eml\"" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g'`
+run perl "$TEST_DIRNAME/cases/scan_file.pl" "path=${_hex_name}"
+check_output 'GTUBE'