From: Lennart Poettering Date: Mon, 19 Feb 2018 16:35:36 +0000 (+0100) Subject: journal-file: refuse opening non-regular journal files X-Git-Tag: v238~82^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8d6a4d33e1c38864b064df39473f4e74ef949b36;p=thirdparty%2Fsystemd.git journal-file: refuse opening non-regular journal files Let's check the file node type when we open/stat journal files: refuse anything that is not a regular file... --- diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 3353b3a0d81..09c511b8b83 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -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; diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c index 4deee461c3f..8a591205c4a 100644 --- a/src/journal/sd-journal.c +++ b/src/journal/sd-journal.c @@ -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;