From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id C4CE1278E5 for ; Thu, 23 May 2024 17:27:24 +0200 (CEST) Received: (qmail 22016 invoked by uid 550); 23 May 2024 15:27:20 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21975 invoked from network); 23 May 2024 15:27:19 -0000 Date: Thu, 23 May 2024 11:27:33 -0400 From: Rich Felker To: Leah Neukirchen Cc: Collin Funk , musl@lists.openwall.com Message-ID: <20240523152733.GB10433@brightrain.aerifal.cx> References: <625e06f9-10ca-4ad3-86e2-6f6edf585ec9@gmail.com> <20240523132117.GZ10433@brightrain.aerifal.cx> <87pltc63rt.fsf@vuxu.org> <20240523144744.GA10433@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XsQoSWH+UP9D9v3l" Content-Disposition: inline In-Reply-To: <20240523144744.GA10433@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] getusershell should ignore comments and empty lines. --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, May 23, 2024 at 10:47:44AM -0400, Rich Felker wrote: > On Thu, May 23, 2024 at 03:45:10PM +0200, Leah Neukirchen wrote: > > Rich Felker writes: > > > > > It says: > > > > > > "A hash mark (``#'') indicates the beginning of a comment; > > > subsequent characters up to the end of the line are not > > > interpreted by the routines which search the file." > > > > > > This isn't very clear whether # is only a comment on the beginning of > > > a line (after potential whitespace?) or whether # appearing in a line > > > with a shell pathname is a comment or part of the pathname. If it's a > > > comment, it's not clear if whitespace before it is part of the shell > > > pathname -- e.g. does "/bin/sh # best shell" define "/bin/sh" or > > > "/bin/sh " as the shell pathname? > > > > > > It sounds like nobody ever thought about whitespace, quoting, or > > > rigorous comment syntax here... > > > > True: > > > > OpenBSD drops the rest of the line with "#" and ignores lines not > > starting with a "/". > > > > glibc drops the rest of the line with "#", elides spaces after the > > entry, and skips everything before the first "/" (quite bold). > > > > pam_shells skips all lines that don't start with a "/" and doesn't > > handle "#" specially. > > > > gnome-terminal just tries to find one line that matches exactly the > > the shell > > > > util-linux skips lines from getusershell that start with "#". > > Likewise "seunshare". > > In general, musl policy is to support at most what's consistent > between historical implementations. > > It seems like they all ignore lines that start with a '#'. They might > (not clear from the above) also ignore blank lines. > > The minimal change both to avoid clashing with vaguely reasonable > things user might want to put there (and violating least surprise), > and to support the common behavior, seems to be just looping as long > as the line is empty or starts with #. Something like this? Rich --XsQoSWH+UP9D9v3l Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="usershell.diff" 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; } --XsQoSWH+UP9D9v3l--