commit a90fc65: [Fix] Do not do `lstat` when we are creating file
Vsevolod Stakhov
vsevolod at rspamd.com
Mon Feb 27 11:00:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-02-27 10:44:22 +0000
URL: https://github.com/rspamd/rspamd/commit/a90fc658d7a2d360bc1b1311f7e5b7e08700c12d
[Fix] Do not do `lstat` when we are creating file
---
src/libutil/util.c | 22 ++++++++++++----------
1 file 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
More information about the Commits
mailing list