aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-02-27 10:44:22 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-02-27 10:44:22 +0000
commita90fc658d7a2d360bc1b1311f7e5b7e08700c12d (patch)
tree06c239d5ec8b91c74a8ce4143389721bf613009d /src/libutil
parent497dd9e2cc2c458c2384e123139a0932db4252d0 (diff)
downloadrspamd-a90fc658d7a2d360bc1b1311f7e5b7e08700c12d.tar.gz
rspamd-a90fc658d7a2d360bc1b1311f7e5b7e08700c12d.zip
[Fix] Do not do `lstat` when we are creating file
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c22
1 files changed, 12 insertions, 10 deletions
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