mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] getusershell: Only return absolute paths
@ 2023-05-16 12:02 Samanta Navarro
  0 siblings, 0 replies; only message in thread
From: Samanta Navarro @ 2023-05-16 12:02 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-16 12:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-16 12:02 [musl] [PATCH] getusershell: Only return absolute paths Samanta Navarro

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).