From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SUBJ_OBFU_PUNCT_FEW autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12670 invoked from network); 14 May 2020 16:35:21 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 14 May 2020 16:35:21 -0000 Received: (qmail 26148 invoked by uid 550); 14 May 2020 16:35:16 -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 26123 invoked from network); 14 May 2020 16:35:15 -0000 Date: Thu, 14 May 2020 12:35:01 -0400 From: Rich Felker To: musl@lists.openwall.com Cc: Cristian Morales Vega Message-ID: <20200514163501.GF21576@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Possible problem with getopt_long_only() On Thu, May 14, 2020 at 10:24:46AM +0100, Cristian Morales Vega wrote: > I have not looked at the details. But killall from psmisc fails to > parse "killall -10 " when using musl 1.1.24 (the one used by the > latest OpenWrt release, according to > https://git.musl-libc.org/cgit/musl/log/src/misc/getopt_long.c the > file has not been changed since 2018-09-12 anyway). > > In https://gitlab.com/psmisc/psmisc/-/blob/v23.3/src/killall.c#L989 > optind is "1" if "killall -10 " was used, but 2 if "killall -9 > ". So whether the signal number is only one digit or more makes > the optind change. So killall only works with <10 signals. It looks like this is not covered by the spec for getopt, but the musl behavior is almost surely the "right" behavior here; what psmisc is expecting makes it impossible to skip over unknown option flags and continue parsing other ones chained together in the same argv[] slot, e.g. -abc where 'a' is unknown but 'b' and 'c' are supported. Trying to use getopt to handle options that are not in the syntax getopt is designed to handle is mostly misguided, but I think it could be fixed by saving optind *before* calling getopt and using the saved optind as the location to look for - followed by digits or capital letters, rather than using optind-1 after getopt returns an error. > Not sure it's the same issue, but in case it's different and was never > reported to you you may be interested also on > https://github.com/JuliaLang/julia/pull/31946. That's a different issue, where musl is clearly doing what's required by the spec and other implementations are buggy; I commented as such on the tracker. Thanks for pointing it out! Rich