From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12428 Path: news.gmane.org!.POSTED!not-for-mail From: Samuel Holland Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 1/2] fix getopt_long arguments to partial matches Date: Mon, 29 Jan 2018 20:36:41 -0600 Message-ID: <20180130023642.2363-1-samuel@sholland.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1517279710 16986 195.159.176.226 (30 Jan 2018 02:35:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 30 Jan 2018 02:35:10 +0000 (UTC) Cc: Samuel Holland To: musl@lists.openwall.com Original-X-From: musl-return-12444-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jan 30 03:35:05 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1egLlF-0003u9-Gd for gllmg-musl@m.gmane.org; Tue, 30 Jan 2018 03:35:01 +0100 Original-Received: (qmail 20043 invoked by uid 550); 30 Jan 2018 02:36:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 19963 invoked from network); 30 Jan 2018 02:36:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=o8FaY5Mhl3jyMhSQ+A65It+prcadYDv2ELIb1CsCR cY=; b=ZRchNzYXFeSbIlCmYw1+0GCu2KVGaC2WFU+uSv4rjtZOTzTN4GyHSNVJ/ QayCYLwmFHLwi4bDP3MY9E+M/NfNH+4d9YK+v7OJKKLIDfqKAyOFduzkZ41Ldhnb Yfh623Sf1M2nsRq+yjVAGaP6PePp5Cc/wv/a3RJNc+6BPe4gPX9ZkJRxg/5oedg6 nTKrfmxFHmOZWRUdaonqGuMxc9bpuBXfimBAg2FKq0xwrlX61i4zHTgDSfpGpoCF ocfMRZMYjako/f/nhL2V8mbWABF/8cvnXk7oIcqd3aLL14239F9q9VqKUlYU9vcD iOiBN3VSbWtTF+zqu8SngcLulHIVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=o8FaY5Mhl3jyMhSQ+ A65It+prcadYDv2ELIb1CsCRcY=; b=MvGAsAO4k6Qxw0erVKvOiMIiE9b3wRlT7 7+tm/ZCJB0Rf1wKCZX5L8yLw9e4Ju5RRf4+CMDx4BpaMjXxZ1mLB+7yxyJTljVmg Bvu8I7SCyoUktrAFBt0IR8glICB+5HjO6vOuS+yxrhEAoXYcUywWZojyoyzYAZCn stBIsfmnBqBteAU8AztTcSZr0/Y3ucg4oTywR6+Ql0Bu8Fose913bk6+fmV5X6Cs 7b07rkPH4a8E3pJ18raC+BlA8Q5pKgE6On2/qg0HmmeA5YBe7BcYhpfkf4qs4NeY uv/vep+vaLRjGa1rWHXcjXs89mDgFLosn/9QmLDnNC32qRnw732rA== X-ME-Sender: X-Mailer: git-send-email 2.13.6 Xref: news.gmane.org gmane.linux.lib.musl.general:12428 Archived-At: If we find a partial option name match, we need to keep looking for ambiguous/conflicting options. However, we need to remember the position in the candidate argument to find its option-argument later, if there is one. This fixes e.g. option "foobar" being given as "--fooba=baz". --- src/misc/getopt_long.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 568ae7ba..0d1501d4 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -58,13 +58,14 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; int i, cnt, match; - char *opt; + char *arg, *opt; for (cnt=i=0; longopts[i].name; i++) { const char *name = longopts[i].name; opt = argv[optind]+1; if (*opt == '-') opt++; for (; *name && *name == *opt; name++, opt++); if (*opt && *opt != '=') continue; + arg = opt; match = i; if (!*name) { cnt = 1; @@ -74,6 +75,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring } if (cnt==1) { i = match; + opt = arg; optind++; if (*opt == '=') { if (!longopts[i].has_arg) { -- 2.13.6