From owner-svn-src-all@freebsd.org Wed Jul 10 22:29:22 2019 Return-Path: Delivered-To: svn-src-all@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 1557715E4F2B for ; Wed, 10 Jul 2019 22:29:22 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8ECB2752BD for ; Wed, 10 Jul 2019 22:29:21 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: by mail-qk1-x742.google.com with SMTP id s145so3251446qke.7 for ; Wed, 10 Jul 2019 15:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=fnXYi2L8bu4DtFWgPbY0xIrmDLl+2QQA+YahJfT6/Kw=; b=XgzsvZtDRNMD0itkh7v0FDzohrXbsWHEyJkjj25pD4ighAytOYuEsbny0VUOjMZ2bo dnFHGe2m5LXfiPt26LWVu6PmSYdtpHeSAJeTIio/PmFa82wrG2FHMrjXgABdrwsf+/AV 6fCNkA/z0z+1YJl6Iucs/2DnrczaBj5gEXL/OYQ3BMzz0ZAn50GnNUgEXTdUl41yc549 RviYcXkQffKHEDyS4xnEdfRWGtpHbQbHamLgFIQ3B1E2nGaHPxRSht2o9Ys3VhcyPi1e BNa//u8DV37D3yWgYHgz6/vTbKYj8ISbWljJbehg0gZqfT/NeDsnP85Qvafz6wcDdJco ptbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=fnXYi2L8bu4DtFWgPbY0xIrmDLl+2QQA+YahJfT6/Kw=; b=hsZjcBSJseTuZ2uMjrNbdSv5Lj2ezcVHr9JjtCIdaWIazMu/bmcjod6HrjFRP5Y42H dkx5v/ipj95PAWDDWYwMnMEiJQGFbJtiYz4ILUnP7qoz4rnq2yJcVZZH96OOZb5hcCuR uXTZ2EyzG7XFl9eP7EBwoRdDxPGOC0M5Zmg5k6Kvty9MluKDWtaQJKAUXn0X807d8CQZ x3eDqmw7ilKtFqU582L+ANVo9f4qj1oaUeHQtA4GRET7FuY76gI/iGQJc9lJxHBGaHCI NnLOzb/Puvbxzd9GgM2Z0QPP5OQnc81KkYprLbqc/SislcYiCYhvSCWp4K0Q/WPW3HGo 9ALw== X-Gm-Message-State: APjAAAWhPzzF9YLIP0V3Vdenm5bBd5/3cuzjk9XPn0BqFBMAW5lIwpMH 44aD59ZOCw8O9IKUWrPB/lKqhQ== X-Google-Smtp-Source: APXvYqybTsfGTWXPmGM8w+29x6SZiIHtby0NhHegp4rWAZyYPbgyuExk6nqmJJ+KTaf1MD8rqIWxgg== X-Received: by 2002:a37:4714:: with SMTP id u20mr484167qka.162.1562797760432; Wed, 10 Jul 2019 15:29:20 -0700 (PDT) Received: from mutt-hbsd ([151.196.118.239]) by smtp.gmail.com with ESMTPSA id o26sm1420409qtp.11.2019.07.10.15.29.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 15:29:19 -0700 (PDT) Date: Wed, 10 Jul 2019 18:29:18 -0400 From: Shawn Webb To: Justin Hibbits Cc: Philip Paeps , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r349890 - head/contrib/telnet/telnet Message-ID: <20190710222918.vj4creizlubdzgw3@mutt-hbsd> References: <201907101742.x6AHg4os016752@repo.freebsd.org> <20190710195548.kdftfemj3icarcxo@mutt-hbsd> <20190710151944.0fd94ec3@titan.knownspace> <20190710202218.yc3lcd6tsql3zkyr@mutt-hbsd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="azbhwo34trcfg3f5" Content-Disposition: inline In-Reply-To: <20190710202218.yc3lcd6tsql3zkyr@mutt-hbsd> X-Operating-System: FreeBSD mutt-hbsd 13.0-CURRENT-HBSD FreeBSD 13.0-CURRENT-HBSD X-PGP-Key: http://pgp.mit.edu/pks/lookup?op=vindex&search=0xFF2E67A277F8E1FA User-Agent: NeoMutt/20180716 X-Rspamd-Queue-Id: 8ECB2752BD X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.99 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.99)[-0.991,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Jul 2019 22:29:22 -0000 --azbhwo34trcfg3f5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 10, 2019 at 04:22:18PM -0400, Shawn Webb wrote: > On Wed, Jul 10, 2019 at 03:19:44PM -0500, Justin Hibbits wrote: > > On Wed, 10 Jul 2019 15:55:48 -0400 > > Shawn Webb wrote: > >=20 > > > On Wed, Jul 10, 2019 at 05:42:04PM +0000, Philip Paeps wrote: > > > > Author: philip > > > > Date: Wed Jul 10 17:42:04 2019 > > > > New Revision: 349890 > > > > URL: https://svnweb.freebsd.org/changeset/base/349890 > > > >=20 > > > > Log: > > > > telnet: fix a couple of snprintf() buffer overflows > > > > =20 > > > > Obtained from: Juniper Networks > > > > MFC after: 1 week > > > >=20 > > > > Modified: > > > > head/contrib/telnet/telnet/commands.c > > > > head/contrib/telnet/telnet/telnet.c > > > > head/contrib/telnet/telnet/utilities.c > > > >=20 > > > > Modified: head/contrib/telnet/telnet/commands.c > > > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D > > > > --- head/contrib/telnet/telnet/commands.c Wed Jul 10 > > > > 17:21:59 2019 (r349889) +++ > > > > head/contrib/telnet/telnet/commands.c Wed Jul 10 17:42:04 > > > > 2019 (r349890) @@ -1655,10 +1655,11 @@ env_init(void) char > > > > hbuf[256+1]; char *cp2 =3D strchr((char *)ep->value, ':'); > > > > =20 > > > > - gethostname(hbuf, 256); > > > > - hbuf[256] =3D '\0'; > > > > - cp =3D (char *)malloc(strlen(hbuf) + strlen(cp2) + > > > > 1); > > > > - sprintf((char *)cp, "%s%s", hbuf, cp2); > > > > + gethostname(hbuf, sizeof(hbuf)); > > > > + hbuf[sizeof(hbuf)-1] =3D '\0'; > > > > + unsigned int buflen =3D strlen(hbuf) + strlen(cp2)= + > > > > 1; =20 > > >=20 > > > buflen should be defined with the rest of the variables in the code > > > block above this one. > >=20 > > Agreed. > >=20 > > >=20 > > > > + cp =3D (char *)malloc(sizeof(char)*buflen); =20 > > >=20 > > > Lack of NULL check here leads to > > >=20 > > > > + snprintf((char *)cp, buflen, "%s%s", hbuf, cp2); =20 > > >=20 > > > potential NULL pointer deref here. > >=20 > > I'm not sure if this is actually a problem. env_init() is called > > exactly once, at the beginning of main(), and the environment size is > > fully constrained by the OS. > >=20 > > That said, this file it the only one in this component that does not > > check the return value of malloc(). All other uses, outside of this > > file, check and error. >=20 > While fixing the style(9) violation above, we could still take care of > the potential NULL deref at the same time. If anything, just for code > correctness reasons? Here's a patch: https://gist.github.com/579685c0252673c3ad92d2536c3486c7 Thanks, --=20 Shawn Webb Cofounder / Security Engineer HardenedBSD Tor-ified Signal: +1 443-546-8752 Tor+XMPP+OTR: lattera@is.a.hacker.sx GPG Key ID: 0xFF2E67A277F8E1FA GPG Key Fingerprint: D206 BB45 15E0 9C49 0CF9 3633 C85B 0AF8 AB23 0FB2 --azbhwo34trcfg3f5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAl0mZrkACgkQ/y5nonf4 4fonOxAAkkmmFdwEviglOgj8Odg8L+UEkbyDxTdH/auvBTfZTAQxMyr/tRaX8n5Q y0mIDhVnWIY1hyMOKtnaH2JvE1sDmLMuYiLY44nIBOzUS5bT2UylhyF3e7r7w9uJ LsMi5Ky0Ap313mhYZwyP0mGsWgU0U+uFwfCdfatV0BZMOX9G1jHXQyMIG/KGWO+Z cErCpJoNhOankh6IFZh5Z0WY8XtKhWwMXDT1AfRse8jHvjTbwmMCMph0bFBOaci2 OauFWvr0zax1dWoWO2EJeDPh2dOF8o0HKfFUkC0RINsKQMxG7sSsfceODl0ORb7k HTJEJXz9TItJC5xlHWkpCVo+UoaL5VFRDaPpEX8i/WYFXj8YKW1P4ah6J5osfVqG ky1BRnJOoRtc7S+EmdQuFZkSv0V1uSKzgp4hH2nDvxRd0xcu5cVJqhJmoCodQCXX nrdiM1cPhwUMgtJlDBZVp1EjRnd290+jRjR5bsoU+XdzkJCE+TiDf5HZw0gDD8Ui Zqcs5ZkiUpKBnsdkya4YI0AWqmtFdCqMqh57452aFwRE7oxxBWBkjJXYnMpwpVvS +ql/areAGV4HxsNz5bZEBv7TwNeYsvNKyEojdUmRfDjdmNOtROQNgYFKzVZO7Qn1 38Uqz/wR/7ymdeiRrSKNq5DlzWsJl8nFSskrSQ9lkMeYCAprYWw= =pPlH -----END PGP SIGNATURE----- --azbhwo34trcfg3f5--