From owner-freebsd-hackers@freebsd.org Mon May 13 06:45:20 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id F040E15AD878 for ; Mon, 13 May 2019 06:45:19 +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 8BB2E6B7C8 for ; Mon, 13 May 2019 06:45:18 +0000 (UTC) (envelope-from sebastian.huber@embedded-brains.de) Received: from [88.198.220.132] (helo=sslproxy03.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1hQ4i3-0007H7-84 for freebsd-hackers@freebsd.org; Mon, 13 May 2019 08:45:15 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1hQ4i3-00086i-0I for freebsd-hackers@freebsd.org; Mon, 13 May 2019 08:45:15 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 3FB112A165C for ; Mon, 13 May 2019 08:45:45 +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 92lX4j57adAv for ; Mon, 13 May 2019 08:45:44 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DB5192A165B for ; Mon, 13 May 2019 08:45:44 +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 JyVDMiIG4tdp for ; Mon, 13 May 2019 08:45:44 +0200 (CEST) Received: from huber-nb-linux.suse (unknown [192.168.96.161]) by mail.embedded-brains.de (Postfix) with ESMTPSA id C886C2A167E for ; Mon, 13 May 2019 08:45:44 +0200 (CEST) Subject: Re: [PATCH] ifconfig: Avoid superfluous write to const string From: Sebastian Huber To: freebsd-hackers@freebsd.org References: <20190513063951.6521-1-sebastian.huber@embedded-brains.de> Message-ID: Date: Mon, 13 May 2019 08:45:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <20190513063951.6521-1-sebastian.huber@embedded-brains.de> 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.100.3/25447/Sun May 12 09:56:54 2019) X-Rspamd-Queue-Id: 8BB2E6B7C8 X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; 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 [-3.04 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_SEVEN(0.00)[8]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:85.10.215.148]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_TLS_LAST(0.00)[]; MX_GOOD(-0.01)[cached: mx.embeddedbrains.de]; NEURAL_HAM_SHORT(-0.39)[-0.386,0]; DMARC_NA(0.00)[embedded-brains.de]; 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.35)[asn: 24940(-1.74), 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: Mon, 13 May 2019 06:45:20 -0000 Sorry, this patch is wrong. The *p =3D '\0' assignment is necessary so=20 that later calls to inet_aton(), gethostbyname() and getnetbyname() work. On 13/05/2019 08:39, Sebastian Huber wrote: > --- > sbin/ifconfig/af_inet.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c > index 3d44a4c0b99..279a31773f4 100644 > --- a/sbin/ifconfig/af_inet.c > +++ b/sbin/ifconfig/af_inet.c > @@ -141,20 +141,18 @@ in_getaddr(const char *s, int which) > sin->sin_family =3D AF_INET; > =20 > if (which =3D=3D ADDR) { > - char *p =3D NULL; > + const char *p =3D strrchr(s, '/'); > =20 > - if((p =3D strrchr(s, '/')) !=3D NULL) { > + if (p !=3D NULL) { > const char *errstr; > /* address is `name/masklen' */ > int masklen; > struct sockaddr_in *min =3D sintab[MASK]; > - *p =3D '\0'; > if (!isdigit(*(p + 1))) > errstr =3D "invalid"; > else > masklen =3D (int)strtonum(p + 1, 0, 32, &errstr); > if (errstr !=3D NULL) { > - *p =3D '/'; > errx(1, "%s: bad value (width %s)", s, errstr); > } > min->sin_family =3D AF_INET; --=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= .