Summary:ASTERISK-27773: Command line not being parsed correctly with getopt not from glibc
Reporter:Guido Falsi (madpilot)Labels:
Date Opened:2018-03-26 06:46:34Date Closed:2018-03-29 10:53:42
Versions:14.7.6 15.0.0 15.3.0 Frequency of
Environment:FreeBSD 11.1Attachments:
Description:Asterisk 15 intriduces a two step command line parsing with getopt(3). Before calling getopt for the second time optind = 0 is called to reset the parsing engine. This works with glibc getopt implementation since it forces optind = 1 when optind == 0 [1]. That's wrong with other implementations not forcing the value to 1.

FreeBSD's getopt when getting optind == 0 checks if argv[0] is an option and since that fails (except the unrealistic case when argv[0][0] == '-') and stops parsing the rest of the command line. [2]

I'm going to file patches on gerrit shortly.

[1] https://github.com/bminor/glibc/blob/2d813d7b77ba8341a0a982d74bb59f5a0d775784/posix/getopt.c#L387

[2] https://github.com/freebsd/freebsd/blob/5c40d602eef148e8d4231cda313ea122738096f4/lib/libc/stdlib/getopt.c#L72
Comments:By: Asterisk Team (asteriskteam) 2018-03-26 06:46:36.274-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Friendly Automation (friendly-automation) 2018-03-29 10:53:43.867-0500

Change 8671 merged by Jenkins2:
core: fix getopt(3) usage


By: Friendly Automation (friendly-automation) 2018-03-29 10:54:04.546-0500

Change 8672 merged by Jenkins2:
core: fix getopt(3) usage