From: Vsevolod Stakhov Date: Mon, 27 Feb 2023 10:44:22 +0000 (+0000) Subject: [Fix] Do not do `lstat` when we are creating file X-Git-Tag: 3.5~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a90fc658d7a2d360bc1b1311f7e5b7e08700c12d;p=thirdparty%2Frspamd.git [Fix] Do not do `lstat` when we are creating file --- diff --git a/src/libutil/util.c b/src/libutil/util.c index bc62bb9193..915d77222c 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