about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2024-06-21 20:54:30 -0400
committerRich Felker <dalias@aerifal.cx>2024-06-21 20:54:30 -0400
commitab31e9d6a0fa7c5c408856c89df2dfb12c344039 (patch)
tree9cb51edb58bab3e0a5875fc18e3cf952ceac0450 /src
parent53ac44ff4c0e91536e1e34e8e59e19d2a1196a67 (diff)
downloadmusl-ab31e9d6a0fa7c5c408856c89df2dfb12c344039.tar.gz
musl-ab31e9d6a0fa7c5c408856c89df2dfb12c344039.tar.xz
musl-ab31e9d6a0fa7c5c408856c89df2dfb12c344039.zip
getusershell: skip blank lines and comments
this interface does not have a lot of historical consensus on how it
handles the contents of the /etc/shells file in regard to whitespace
and comments, but the commonality between all checked is that they
ignore lines that are blank or that begin with '#', so that is the
behavior we adopt.
Diffstat (limited to 'src')
-rw-r--r--src/legacy/getusershell.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/legacy/getusershell.c b/src/legacy/getusershell.c
index 5fecdec2..1c5d98ec 100644
--- a/src/legacy/getusershell.c
+++ b/src/legacy/getusershell.c
@@ -25,8 +25,10 @@ char *getusershell(void)
 	ssize_t l;
 	if (!f) setusershell();
 	if (!f) return 0;
-	l = getline(&line, &linesize, f);
-	if (l <= 0) return 0;
+	do {
+		l = getline(&line, &linesize, f);
+		if (l <= 0) return 0;
+	} while (line[0] == '#' || line[0] == '\n');
 	if (line[l-1]=='\n') line[l-1]=0;
 	return line;
 }