journal-file: refuse opening non-regular journal files
authorLennart Poettering <lennart@poettering.net>
Mon, 19 Feb 2018 16:35:36 +0000 (17:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Feb 2018 11:53:10 +0000 (12:53 +0100)
Let's check the file node type when we open/stat journal files: refuse
anything that is not a regular file...

src/journal/journal-file.c
src/journal/sd-journal.c

index 3353b3a..09c511b 100644 (file)
@@ -651,6 +651,12 @@ static int journal_file_fstat(JournalFile *f) {
 
         f->last_stat_usec = now(CLOCK_MONOTONIC);
 
+        /* Refuse dealing with with files that aren't regular */
+        if (S_ISDIR(f->last_stat.st_mode))
+                return -EISDIR;
+        if (!S_ISREG(f->last_stat.st_mode))
+                return -EBADFD;
+
         /* Refuse appending to files that are already deleted */
         if (f->last_stat.st_nlink <= 0)
                 return -EIDRM;
index 4deee46..8a59120 100644 (file)
@@ -2016,6 +2016,10 @@ _public_ int sd_journal_open_files_fd(sd_journal **ret, int fds[], unsigned n_fd
                         goto fail;
                 }
 
+                if (S_ISDIR(st.st_mode)) {
+                        r = -EISDIR;
+                        goto fail;
+                }
                 if (!S_ISREG(st.st_mode)) {
                         r = -EBADFD;
                         goto fail;