From: <writeonce@midipix.org>
To: musl@lists.openwall.com
Subject: RE: bug in getopt_long()
Date: Sat, 07 Jan 2017 09:31:47 -0700 [thread overview]
Message-ID: <20170107093147.dc30d64f61e5ec441c34ffd4f788e58e.a683212f25.wbe@email15.godaddy.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1753 bytes --]
>
>
> -------- Original Message --------
> Subject: RE: [musl] bug in getopt_long()
> From: <writeonce@midipix.org>
> Date: Sat, January 07, 2017 8:13 am
> To: musl@lists.openwall.com
>
>
> >
> >
> > -------- Original Message --------
> > Subject: [musl] bug in getopt_long()
> > From: "Anthony G. Basile" <basile@freeharbor.net>
> > Date: Thu, January 05, 2017 9:00 am
> > To: musl@lists.openwall.com
> >
> > Hi,
> >
> > We hit a bug in Gentoo with getopt_long(). It appears the alpine people
> > hit it too http://bugs.alpinelinux.org/issues/4802. The problem was
> > encountered in open-iscsi but I got some reduced code which I've
> > attached. If you build and run that code as `./test --portal
> > 10.144.0.14 --discover` then you get
> >
> > p
> > D
> > unrecognized character 'D'
> >
> > On a glibc system, you don't get the "unrecognized character 'D'" which
> > is what we'd expect. Rich suggested a patch to musl which looked like
> > it might work, but it didn't. I didn't investigate further. I'm just
> > reporting it first to see if others know what's up.
> >
>
> The attached patch should work, I believe; tested with both of the
> following:
>
> ./a.out --portal 10.144.0.14 --discover
> ./a.out --portal 10.144.0.14 --discover -- foo bar
Behavior after my original patch deviated from glibc in the following
case:
./a.out -a -b -c -d -e --discover
The attached updated patch should do the trick for all three cases.
midipix
>
> midipix
>
>
> >
> > --
> > Anthony G. Basile, Ph.D.
> > Gentoo Linux Developer [Hardened]
> > E-Mail : basile@freeharbor.net
> > GnuPG FP : 1FED FAD9 D82C 52A5 3BAB DC79 9384 FA6E F52D 4BBA
> > GnuPG ID : F52D4BBA
> >
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: getopt_long_v2.patch --]
[-- Type: text/x-diff; name="getopt_long_v2.patch";, Size: 1275 bytes --]
From f2aaead9a6f5595f20728e5582574e50adac9308 Mon Sep 17 00:00:00 2001
From: midipix <writeonce@midipix.org>
Date: Sat, 7 Jan 2017 09:43:10 -0500
Subject: [PATCH] getopt_long(): record successful completed parsing of all
arguments.
---
src/misc/getopt_long.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index 568ae7b..d20d4f3 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -5,6 +5,7 @@
#include <string.h>
extern int __optpos, __optreset;
+static int __getopt_err = 0;
static void permute(char *const *argv, int dest, int src)
{
@@ -26,8 +27,13 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con
if (!optind || __optreset) {
__optreset = 0;
__optpos = 0;
+ __getopt_err = 0;
optind = 1;
}
+ if (optind == argc && !__getopt_err) {
+ optopt = 0;
+ return -1;
+ }
if (optind >= argc || !argv[optind]) return -1;
skipped = optind;
if (optstring[0] != '+' && optstring[0] != '-') {
@@ -46,6 +52,7 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con
permute(argv, skipped, optind-1);
optind = skipped + cnt;
}
+ __getopt_err |= ((ret == '?') || (ret == ':'));
return ret;
}
--
2.8.3
next reply other threads:[~2017-01-07 16:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-07 16:31 writeonce [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-01-07 15:13 writeonce
2017-01-05 16:00 Anthony G. Basile
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170107093147.dc30d64f61e5ec441c34ffd4f788e58e.a683212f25.wbe@email15.godaddy.com \
--to=writeonce@midipix.org \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).