From owner-freebsd-hackers@freebsd.org Fri Sep 13 05:53:51 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7C12CE63CC for ; Fri, 13 Sep 2019 05:53:51 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46V4ZQ12dKz4BSJ for ; Fri, 13 Sep 2019 05:53:49 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from sslproxy06.your-server.de ([78.46.172.3]) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1i8eWg-00064H-9J; Fri, 13 Sep 2019 07:53:46 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy06.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1i8eWg-0005Gl-4q; Fri, 13 Sep 2019 07:53:46 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 96ADC2A000F; Fri, 13 Sep 2019 07:53:53 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id dA-fUd93IEgW; Fri, 13 Sep 2019 07:53:53 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 29CAF2A1682; Fri, 13 Sep 2019 07:53:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 6LGkP0X3Cshs; Fri, 13 Sep 2019 07:53:53 +0200 (CEST) Received: from huber-nb-linux.suse (unknown [192.168.96.161]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 14FE22A000F; Fri, 13 Sep 2019 07:53:51 +0200 (CEST) Subject: Re: [PATCH] nvmecontrol: Fix shortopts allocation To: Warner Losh Cc: "freebsd-hackers@freebsd.org" References: <20190911082833.32388-1-sebastian.huber@embedded-brains.de> From: Sebastian Huber Message-ID: Date: Fri, 13 Sep 2019 07:53:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.101.4/25570/Thu Sep 12 10:22:52 2019) X-Rspamd-Queue-Id: 46V4ZQ12dKz4BSJ X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of sebastian.huber@embedded-brains.de designates 85.10.215.148 as permitted sender) smtp.mailfrom=sebastian.huber@embedded-brains.de X-Spamd-Result: default: False [-2.29 / 15.00]; ARC_NA(0.00)[]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_COUNT_SEVEN(0.00)[8]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:85.10.215.148]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; DMARC_NA(0.00)[embedded-brains.de]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[148.215.10.85.list.dnswl.org : 127.0.10.0]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; IP_SCORE(0.00)[ipnet: 85.10.192.0/18(1.82), asn: 24940(-1.79), country: DE(-0.01)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:85.10.192.0/18, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; HAS_X_AS(0.00)[] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Sep 2019 05:53:51 -0000 On 11/09/2019 15:30, Warner Losh wrote: >=20 >=20 > On Wed, Sep 11, 2019 at 2:28 AM Sebastian Huber=20 > > wrote: >=20 > Account for potential ':' in the short options string. > --- > =C2=A0sbin/nvmecontrol/comnd.c | 2 +- > =C2=A01 file changed, 1 insertion(+), 1 deletion(-) >=20 > diff --git a/sbin/nvmecontrol/comnd.c b/sbin/nvmecontrol/comnd.c > index d8d97ad11b5..a91969ff766 100644 > --- a/sbin/nvmecontrol/comnd.c > +++ b/sbin/nvmecontrol/comnd.c > @@ -189,7 +189,7 @@ arg_parse(int argc, char * const * argv, const > struct cmd *f) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 lopts =3D malloc((n + 2) * sizeof(stru= ct option)); > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (lopts =3D=3D NULL) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 err(1, "op= tion memory"); > -=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D shortopts =3D malloc((n + 3) * si= zeof(char)); > +=C2=A0 =C2=A0 =C2=A0 =C2=A0p =3D shortopts =3D malloc((2 * n + 2) = * sizeof(char)); >=20 >=20 > I'll apply, but I still think this needs to be=C2=A0+ 3 to account for = the=20 > NUL at the end (even though we kinda know that the 2 options we're=20 > adding don't have :. Thanks for checking it in. I wondered why there was a + 3, we have in=20 arg_parse() with unrelated code omitted: p =3D shortopts =3D malloc((2 * n + 3) * sizeof(char)); for (i =3D 0; i < n; i++) { if (isprint(opts[i].short_arg)) { *p++ =3D opts[i].short_arg; if (lopts[i].has_arg) *p++ =3D ':'; } } *p++ =3D '?'; *p++ =3D '\0'; while ((ch =3D getopt_long(argc, argv, shortopts, lopts, &idx)) !=3D -1) = { Looks like the last ++ is superfluous. --=20 Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.huber@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG= .