|
Message-ID: <rxo7uf6e2liiwp7zshikaqljkao6gqnpch36wyofayhbackbhn@47hbeezyi2wv> Date: Tue, 16 May 2023 12:02:39 +0000 From: Samanta Navarro <ferivoz@...eup.net> To: musl@...ts.openwall.com Subject: [PATCH] getusershell: Only return absolute paths Also strip comments to be compatible with other getusershell implementations (glibc, *BSD). Running `chsh -l` of util-linux built with musl is effectively a `cat /etc/shells`. Signed-off-by: Samanta Navarro <ferivoz@...eup.net> --- src/legacy/getusershell.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/legacy/getusershell.c b/src/legacy/getusershell.c index 5fecdec2..81e872df 100644 --- a/src/legacy/getusershell.c +++ b/src/legacy/getusershell.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE #include <stdio.h> +#include <string.h> #include <unistd.h> static const char defshells[] = "/bin/sh\n/bin/csh\n"; @@ -22,11 +23,12 @@ void setusershell(void) char *getusershell(void) { - ssize_t l; if (!f) setusershell(); if (!f) return 0; - l = getline(&line, &linesize, f); - if (l <= 0) return 0; - if (line[l-1]=='\n') line[l-1]=0; + do { + ssize_t l = getline(&line, &linesize, f); + if (l <= 0) return 0; + } while (line[0] != '/'); + line[strcspn(line, "#\n")] = 0; return line; } -- 2.40.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.