Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Thu, 13 Oct 2016 13:03:16 -0500
From: "Sidney Manning" <sidneym@...eaurora.org>
To: <musl@...ts.openwall.com>
Subject: RE: getopt_long_only

> -----Original Message-----
> From: Sidney Manning [mailto:sidneym@...eaurora.org]
> Sent: Thursday, October 13, 2016 9:43 AM
> To: 'musl@...ts.openwall.com' <musl@...ts.openwall.com>
> Subject: getopt_long_only
> 
> I may have found an issue with this API.  When a double hyphen is
> encountered the API is supposed to return a -1 but I'm seeing a '?'.
> 
> My reference is from the Solaris docs which say: "The special option "--"
can
> be used to delimit the end of the options; when it is encountered, -1 is
> returned and "--" is skipped.  I attached a test case to show the problem.
> 
> I made the following change it will cause the code to punt to getopt when
> just  a "--" is found:
> argv[optind][0] == '-'
> argv[optind][1] == '-'
> argv[optind][2] == NULL
> 
> diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index
> 480c001..9764f56 100644
> --- a/src/misc/getopt_long.c
> +++ b/src/misc/getopt_long.c
> @@ -53,7 +53,7 @@ static int __getopt_long_core(int argc, char *const
> *argv, con  {
>         optarg = 0;
>         if (longopts && argv[optind][0] == '-' &&
> -               ((longonly && argv[optind][1]) ||
> +               ((longonly && argv[optind][1]) &&

It was pointed out to me that, "--" is a special case and should be treated
as such (and the above change is wrong)
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -52,6 +52,10 @@ static int __getopt_long(int argc, char *const *argv,
const char *optstring, con
 static int __getopt_long_core(int argc, char *const *argv, const char
*optstring, const struct option *longopts, int *idx, int longonly)
 {
        optarg = 0;
+       if (longopts && argv[optind][0] == '-' && argv[optind][1] == '-' &&
+            !argv[optind][2])
+               return getopt(argc, argv, optstring);
+
        if (longopts && argv[optind][0] == '-' &&
                ((longonly && argv[optind][1]) ||
                 (argv[optind][1] == '-' && argv[optind][2])))


 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation


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.