]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: only print regular files for motd
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 10 Jan 2026 21:56:45 +0000 (22:56 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 10 Jan 2026 22:02:43 +0000 (23:02 +0100)
The existing code tries to only print content of non-empty files, but
does not check the target of an encountered symbolic link, which could
be even something else, e.g. a fifo. Add the missing check to the
motddir_filter function.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
login-utils/login.c

index dd2e87dc989ffc12edd807e6214014c4b7e8f70b..66f81516a65316a5643ca43493591842732cd6b1 100644 (file)
@@ -296,6 +296,7 @@ static const char *get_thishost(struct login_context *cxt, const char **domain)
 #ifdef MOTDDIR_SUPPORT
 static int motddir_filter(const struct dirent *d)
 {
+       struct stat st;
        size_t namesz;
 
 #ifdef _DIRENT_HAVE_D_TYPE
@@ -311,6 +312,11 @@ static int motddir_filter(const struct dirent *d)
            strcmp(d->d_name + (namesz - MOTDDIR_EXTSIZ), MOTDDIR_EXT) != 0)
                return 0;
 
+       if (stat(d->d_name, &st) < 0)
+               return 0;
+       if (!S_ISREG(st.st_mode) || st.st_size == 0)
+               return 0;
+
        return 1; /* accept */
 }