From a90fc658d7a2d360bc1b1311f7e5b7e08700c12d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 27 Feb 2023 10:44:22 +0000 Subject: [Fix] Do not do `lstat` when we are creating file --- src/libutil/util.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/libutil') diff --git a/src/libutil/util.c b/src/libutil/util.c index bc62bb919..915d77222 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -1872,21 +1872,23 @@ rspamd_file_xopen (const char *fname, int oflags, guint mode, struct stat sb; int fd, flags = oflags; - if (lstat (fname, &sb) == -1) { + if (!(oflags & O_CREAT)) { + if (lstat(fname, &sb) == -1) { - if (errno != ENOENT) { - return (-1); + if (errno != ENOENT) { + return (-1); + } } - } - else if (!S_ISREG (sb.st_mode)) { - if (S_ISLNK (sb.st_mode)) { - if (!allow_symlink) { + else if (!S_ISREG (sb.st_mode)) { + if (S_ISLNK (sb.st_mode)) { + if (!allow_symlink) { + return -1; + } + } + else { return -1; } } - else { - return -1; - } } #ifdef HAVE_OCLOEXEC -- cgit v1.2.3