Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 14 May 2020 12:35:01 -0400
From: Rich Felker <>
Cc: Cristian Morales Vega <>
Subject: Re: 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 <cmd>" when using musl 1.1.24 (the one used by the
> latest OpenWrt release, according to
> the
> file has not been changed since 2018-09-12 anyway).
> In
> optind is "1" if "killall -10 <cmd>" was used, but 2 if "killall -9
> <cmd>". 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

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!


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.