Hi Bruno,
I setup an Alpine VM and looked into the getusershell () failure you
reported earlier.
On alpine the default /etc/shells:
# valid login shells
/bin/sh
/bin/ash
/bin/bash
Fails because of the comment as I explained earlier. When adding a few
blank lines before the comment and an assertion:
$ ./gltests/test-getusershell
test-getusershell.c:55: assertion 'ptr[0] != '\0'' failed
Aborted
This differs from Glibc's behavior where empty lines are ignored. It
looks like Glibc is lightly modified from 4.4BSD's sources since
FreeBSD's code looks similar in that area. I've pushed the attached
patch checking for empty lines since all the other BSDs likely pass it
too.
I'll submit a bug report on the musl lists now. I don't think this
function is used too much, but it seems sort of bad that a default
/etc/shells starts with a comment which is then returned upon the
first call...
Collin
From f77eb82cec43e043762c7e746375bc1879aa4849 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Fri, 17 May 2024 18:53:51 -0700
Subject: [PATCH] getusershell tests: Fail if empty lines are returned.
* tests/test-getusershell.c (first_pass): Check the result of malloc.
Make sure '\0' isn't returned from getusershell when there is an empty
line in /etc/shells.
---
ChangeLog | 7 +++++++
tests/test-getusershell.c | 4 +++-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 888ab7fdd7..e1a840eb04 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-05-17 Collin Funk <collin.fu...@gmail.com>
+
+ getusershell tests: Fail if empty lines are returned.
+ * tests/test-getusershell.c (first_pass): Check the result of malloc.
+ Make sure '\0' isn't returned from getusershell when there is an empty
+ line in /etc/shells.
+
2024-05-17 Bruno Haible <br...@clisp.org>
unistd: Fix compilation error with MSVC in C++ mode.
diff --git a/tests/test-getusershell.c b/tests/test-getusershell.c
index f009e8902a..ea9d7ac6ed 100644
--- a/tests/test-getusershell.c
+++ b/tests/test-getusershell.c
@@ -46,11 +46,13 @@ first_pass (void)
/* Avoid reallocation. */
shell_count = 16;
shells = malloc (shell_count * sizeof (char *));
+ ASSERT (shells != NULL);
for (; (ptr = getusershell ()); ++i)
{
- /* Make sure comments are ignored. */
+ /* Make sure comments and empty lines are ignored. */
ASSERT (ptr[0] != '#');
+ ASSERT (ptr[0] != '\0');
if (i >= shell_count)
{
shell_count *= 2;
--
2.45.1