From owner-svn-src-head@freebsd.org Sat Jan 27 22:31:13 2018 Return-Path: Delivered-To: svn-src-head@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 D7404EC7022; Sat, 27 Jan 2018 22:31:13 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "tensor.andric.com", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 70B847CF84; Sat, 27 Jan 2018 22:31:13 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from coleburn.home.andric.com (coleburn.home.andric.com [192.168.0.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 36756EF59; Sat, 27 Jan 2018 23:31:12 +0100 (CET) From: Dimitry Andric Message-Id: <7C471160-44B3-4EA6-8995-08A4EB4332A1@FreeBSD.org> Content-Type: multipart/signed; boundary="Apple-Mail=_1FA37D74-6C1D-48F2-B90D-FF51BAB1973D"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: svn commit: r328492 - head/contrib/opie/libopie Date: Sat, 27 Jan 2018 23:31:11 +0100 In-Reply-To: Cc: "Pedro F. Giffuni" , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org To: Ed Schouten References: <201801272216.w0RMGJwo057492@repo.freebsd.org> X-Mailer: Apple Mail (2.3273) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Jan 2018 22:31:14 -0000 --Apple-Mail=_1FA37D74-6C1D-48F2-B90D-FF51BAB1973D Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii On 27 Jan 2018, at 23:20, Ed Schouten wrote: > > 2018-01-27 23:16 GMT+01:00 Pedro F. Giffuni : >> char host[sizeof(utmp.ut_host) + 1]; >> insecure = 1; >> >> - strncpy(host, utmp.ut_host, sizeof(utmp.ut_host)); >> - host[sizeof(utmp.ut_host)] = 0; >> + strncpy(host, utmp.ut_host, sizeof(host)); > > Wait... This may access utmp.ut_host one byte past the end and no > longer guarantees that host is null-terminated, right? No, strncpy "copies at most len characters from src into dst". However, if the length of the source is equal to or greater than len, the destination is *not* null terminated. This is likely why the "host[sizeof(utmp.ut_host)] = 0;" statement was added. In any case, this is why strlcpy exists. :) -Dimitry --Apple-Mail=_1FA37D74-6C1D-48F2-B90D-FF51BAB1973D Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.2 iF0EARECAB0WIQR6tGLSzjX8bUI5T82wXqMKLiCWowUCWmz9rwAKCRCwXqMKLiCW ozvjAJwOzX8s9AFtYs55JtxbfsyJl3NHUwCZAVBzD3h33L0t/vC4Q1gNTs2A9es= =aCkh -----END PGP SIGNATURE----- --Apple-Mail=_1FA37D74-6C1D-48F2-B90D-FF51BAB1973D--