]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
chsh: limit acceptable shells to absolute paths
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 11 Nov 2023 22:10:55 +0000 (23:10 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 27 Nov 2023 08:16:08 +0000 (09:16 +0100)
If an entry in /etc/shells is not an absolute path (comments or
partial reads due to fgets), the line should not be considered as
a valid login shell.

In general all systems should have getusershells, but let's better
be safe than sorry.

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

index c11195ff939cae21e4f212ae7cd9757e959469ff..3ae8b5108a30d574e3eb1179920f6ab7e230eaba 100644 (file)
@@ -204,21 +204,17 @@ static bool shell_is_listed (const char *sh)
        }
        endusershell ();
 #else
-       char buf[BUFSIZ];
+       char *buf = NULL;
        FILE *fp;
+       size_t n = 0;
 
        fp = fopen (SHELLS_FILE, "r");
        if (NULL == fp) {
                return false;
        }
 
-       while (fgets (buf, sizeof (buf), fp) == buf) {
-               cp = strrchr (buf, '\n');
-               if (NULL != cp) {
-                       *cp = '\0';
-               }
-
-               if (buf[0] == '#') {
+       while (getline (&buf, &n, fp) != -1) {
+               if (buf[0] != '/') {
                        continue;
                }
 
@@ -227,6 +223,8 @@ static bool shell_is_listed (const char *sh)
                        break;
                }
        }
+
+       free(buf);
        fclose (fp);
 #endif
        return found;