diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-09 13:59:56 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-05-09 14:06:40 +0100 |
commit | 4c2c4f0fdc54f9bdb5371a108c3dc7886e6c81ec (patch) | |
tree | 731e32b41934b03c0d7fc802f57e76eb58ea2cb1 /src/libutil/util.c | |
parent | 7b0d41173904268944de296ab85f20efef91bde5 (diff) | |
download | rspamd-4c2c4f0fdc54f9bdb5371a108c3dc7886e6c81ec.tar.gz rspamd-4c2c4f0fdc54f9bdb5371a108c3dc7886e6c81ec.zip |
[Fix] Allow to follow symlinks when safe
Issue: #1625
Diffstat (limited to 'src/libutil/util.c')
-rw-r--r-- | src/libutil/util.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c index 704d65041..593baf522 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -2114,7 +2114,7 @@ rspamd_open_zstd_dictionary (const char *path) struct zstd_dictionary *dict; dict = g_slice_alloc0 (sizeof (*dict)); - dict->dict = rspamd_file_xmap (path, PROT_READ, &dict->size); + dict->dict = rspamd_file_xmap (path, PROT_READ, &dict->size, TRUE); if (dict->dict == NULL) { g_slice_free1 (sizeof (*dict), dict); @@ -2418,7 +2418,8 @@ event_get_base (struct event *ev) #endif int -rspamd_file_xopen (const char *fname, int oflags, guint mode) +rspamd_file_xopen (const char *fname, int oflags, guint mode, + gboolean allow_symlink) { struct stat sb; int fd; @@ -2434,7 +2435,12 @@ rspamd_file_xopen (const char *fname, int oflags, guint mode) } #ifdef HAVE_ONOFOLLOW - fd = open (fname, oflags | O_NOFOLLOW, mode); + if (!allow_symlink) { + fd = open (fname, oflags | O_NOFOLLOW, mode); + } + else { + fd = open (fname, oflags, mode); + } #else fd = open (fname, oflags, mode); #endif @@ -2443,8 +2449,8 @@ rspamd_file_xopen (const char *fname, int oflags, guint mode) } gpointer -rspamd_file_xmap (const char *fname, guint mode, - gsize *size) +rspamd_file_xmap (const char *fname, guint mode, gsize *size, + gboolean allow_symlink) { gint fd; struct stat sb; @@ -2454,10 +2460,10 @@ rspamd_file_xmap (const char *fname, guint mode, g_assert (size != NULL); if (mode & PROT_WRITE) { - fd = rspamd_file_xopen (fname, O_RDWR, 0); + fd = rspamd_file_xopen (fname, O_RDWR, 0, allow_symlink); } else { - fd = rspamd_file_xopen (fname, O_RDONLY, 0); + fd = rspamd_file_xopen (fname, O_RDONLY, 0, allow_symlink); } if (fd == -1) { |