From: Samanta Navarro <ferivoz@riseup.net>
To: musl@lists.openwall.com
Subject: [musl] [PATCH] getusershell: Only return absolute paths
Date: Tue, 16 May 2023 12:02:39 +0000 [thread overview]
Message-ID: <rxo7uf6e2liiwp7zshikaqljkao6gqnpch36wyofayhbackbhn@47hbeezyi2wv> (raw)
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@riseup.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
reply other threads:[~2023-05-16 12:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=rxo7uf6e2liiwp7zshikaqljkao6gqnpch36wyofayhbackbhn@47hbeezyi2wv \
--to=ferivoz@riseup.net \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).