]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fileio: add new flag READ_FULL_FILE_VERIFY_REGULAR() that checks if file we operate...
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Jun 2024 12:55:24 +0000 (14:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 2 Nov 2025 20:14:35 +0000 (21:14 +0100)
src/basic/fileio.c
src/basic/fileio.h

index 5d9ccbfb8488e8f833be4a443baecb1e09b01a25..a493384c52de42bd7575f38e5ecc942262682bc8 100644 (file)
@@ -664,6 +664,12 @@ int read_full_stream_full(
                 if (fstat(fd, &st) < 0)
                         return -errno;
 
+                if (FLAGS_SET(flags, READ_FULL_FILE_VERIFY_REGULAR)) {
+                        r = stat_verify_regular(&st);
+                        if (r < 0)
+                                return r;
+                }
+
                 if (S_ISREG(st.st_mode)) {
 
                         /* Try to start with the right file size if we shall read the file in full. Note
@@ -685,7 +691,8 @@ int read_full_stream_full(
                         if (flags & READ_FULL_FILE_WARN_WORLD_READABLE)
                                 (void) warn_file_is_world_accessible(filename, &st, NULL, 0);
                 }
-        }
+        } else if (FLAGS_SET(flags, READ_FULL_FILE_VERIFY_REGULAR))
+                return -EBADFD;
 
         /* If we don't know how much to read, figure it out now. If we shall read a part of the file, then
          * allocate the requested size. If we shall load the full file start with LINE_MAX. Note that if
index 96a8773620ccc3bf80690e8bdde31314059a9234..578c16c0ee394bde2ff5219cea914beb2cc3f126 100644 (file)
@@ -30,6 +30,7 @@ typedef enum {
         READ_FULL_FILE_WARN_WORLD_READABLE = 1 << 3, /* if regular file, log at LOG_WARNING level if access mode above 0700 */
         READ_FULL_FILE_CONNECT_SOCKET      = 1 << 4, /* if socket inode, connect to it and read off it */
         READ_FULL_FILE_FAIL_WHEN_LARGER    = 1 << 5, /* fail loading if file is larger than specified size */
+        READ_FULL_FILE_VERIFY_REGULAR      = 1 << 6, /* before reading, verify this is a regular file */
 } ReadFullFileFlags;
 
 int fdopen_unlocked(int fd, const char *options, FILE **ret);