From owner-svn-src-all@freebsd.org Wed Jul 10 22:43:45 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 D2B6415E5480 for ; Wed, 10 Jul 2019 22:43:44 +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 38AD675E6D for ; Wed, 10 Jul 2019 22:43:44 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: by mail-qk1-x742.google.com with SMTP id t8so3299222qkt.1 for ; Wed, 10 Jul 2019 15:43:44 -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=KgZFzH1i+QylvYKNXWozjp50iP59a407g+mtKDPZH9Y=; b=DasIPif16NijjRZ/ceRzRCZ+h8ArS5YonGPafxeol6d5A/fWLqIZdgC9FTg+6c0KX7 9+4F+JFcyTOj+2nukmuR0dSUHGwk4vSCy0q1676GzmLVLqfDP2LttreUZQ8wQbfdtohf 5LL4vzXWzg9eplYEXWlxkZtur0iI6hnGriUJEG75AYf1fxayIy2GpCDuZSGuFwnYqQ4n +R7Dqe0Qc5MqFVxWoBP5ArMo4N/cEyE3Yyze8j8JrJQghIdc8XFNSD50p+4YL2TzbYVG rIK9zQyct+kuOksFWpfTmBkbF5toR8Z01i0+kCOqIJMG6hnkvL9gst7gc1lBMOXaypdV QNRw== 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=KgZFzH1i+QylvYKNXWozjp50iP59a407g+mtKDPZH9Y=; b=B2cA3tzwSK7jb4bfG1wAOEm+N19u6uSMfHmBFAmTUFvRxrGOg9wSP/ETx8QQw1A6SW zwvVAe9kYPTP0ZxBTQvLJ/3BhZwtUQecklUUd6qXcR8AUlbkLBSnm4B+tYs6ohw0PLmV Xt4Gvscs/GC3DRq+Z+Dn7GU9MSgzEZQU9gnpSJheaT++QoUNr8AUYENKUHptWA2nomWB DbP7TT5TSTXcIsTy64YVRZGxbQuz/o7S0X7YtcRzqCs0zuX/8k9AOM4dU2yKFJyyEvhA GwvTBrMx08DSaYh59QFGR14qsj2Uzb52iZsmy1g8N8Z4rlT5aj4bt7dw3mpx0TB7glRI AYdA== X-Gm-Message-State: APjAAAXZxBVeSGmJvtfuzyU+SuvY1wc+GJ+dVHxxATH+cOdbjPVYuDMS 6wINANtjodbZpJEqOO3KRgwzCw== X-Google-Smtp-Source: APXvYqzJnWvkHDl0H3ZOec8Su/ADyHsyA88ltHX1xEn5JcoAfXd22fNe57+zAsHE+kdUClcSd4vkgw== X-Received: by 2002:a37:6944:: with SMTP id e65mr463062qkc.119.1562798623150; Wed, 10 Jul 2019 15:43:43 -0700 (PDT) Received: from mutt-hbsd ([151.196.118.239]) by smtp.gmail.com with ESMTPSA id n184sm1635739qkc.114.2019.07.10.15.43.41 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 10 Jul 2019 15:43:42 -0700 (PDT) Date: Wed, 10 Jul 2019 18:43:41 -0400 From: Shawn Webb To: Warner Losh Cc: Justin Hibbits , Philip Paeps , src-committers , svn-src-all , svn-src-head Subject: Re: svn commit: r349890 - head/contrib/telnet/telnet Message-ID: <20190710224341.i3rbhapmpdw6gkbd@mutt-hbsd> References: <201907101742.x6AHg4os016752@repo.freebsd.org> <20190710195548.kdftfemj3icarcxo@mutt-hbsd> <20190710151944.0fd94ec3@titan.knownspace> <20190710202218.yc3lcd6tsql3zkyr@mutt-hbsd> <20190710222918.vj4creizlubdzgw3@mutt-hbsd> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ac2c4ewsv4bdieh7" Content-Disposition: inline In-Reply-To: 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: 38AD675E6D 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:43:45 -0000 --ac2c4ewsv4bdieh7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 10, 2019 at 04:40:25PM -0600, Warner Losh wrote: > On Wed, Jul 10, 2019 at 4:29 PM Shawn Webb > wrote: >=20 > > 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: > > > > > > > > > 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 > > > > > > > > > > > > Log: > > > > > > telnet: fix a couple of snprintf() buffer overflows > > > > > > > > > > > > Obtained from: Juniper Networks > > > > > > MFC after: 1 week > > > > > > > > > > > > Modified: > > > > > > head/contrib/telnet/telnet/commands.c > > > > > > head/contrib/telnet/telnet/telnet.c > > > > > > head/contrib/telnet/telnet/utilities.c > > > > > > > > > > > > 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, ':'); > > > > > > > > > > > > - 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; > > > > > > > > > > buflen should be defined with the rest of the variables in the co= de > > > > > block above this one. > > > > > > > > Agreed. > > > > > > > > > > > > > > > + cp =3D (char *)malloc(sizeof(char)*buflen); > > > > > > > > > > Lack of NULL check here leads to > > > > > > > > > > > + snprintf((char *)cp, buflen, "%s%s", hbuf, cp2); > > > > > > > > > > potential NULL pointer deref here. > > > > > > > > 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. > > > > > > > > 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. > > > > > > 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 >=20 >=20 > Any reason to not use asprintf instead of malloc + snprintf? Because the existing code already used malloc + snprintf. And this is contrib/telnet/telnet, which arguably should be `rm -rf`ed. ;) The bike shed is now glow-in-the-dark neon green. 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 --ac2c4ewsv4bdieh7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAl0mahcACgkQ/y5nonf4 4fr/jA//RimSOU70RBT1Nd1RxIDlTLZGfwXvN8F8SL3OW+H2FhP+J0UvCzNghszj 8ox5RnWFsZa2WZckTd3zz3FSqUvt5WjNWD1JLSvCBJtTg4alfLkP6MUmCwVeHM/I JZVaOCzHcTr0W+hIq/QrkVcPMZJEm78INuDtn8rRtqp01foh5Wtea0hB5xaPC+DG CIvT2fhOue0eRkKSpc6xaeOSvaH3xHoOWLHRMniY4Moy3EoPpgRL/99ID+0ihaOA 4iD/ynMbJH9ClaKtkjgYi3Zy75vbmF+oNCMIIdHbG9+O0djtJ+xdJkXIzD1XIqoA YbUPE54svJ/Lk5jHKMtF+6b6bAdVbOGOrTedPTKW0y6CEIfB7KWz1dCYtNwltKQG /728n1AP6xQjySy8T5NwxSb7bQyC+FD0OeBOK4kgBSWQQIGonBKFCh4IswPP4RBk x8kShM5ILAClMhSZHYXMCoQEAY6Ia0zlRf2pAvYf08aGcNtsc0Qrg8X4ShHdBFEG 3SXNii9O7ikKNOl4oWOSISiXprzSTEm84OzJ3BiEdfl6QVqkipUrYmfm5lL3ZyI8 XSFjzlZ8hTwZ/KXtV/O46q+ZD/9BN35qIN1Jo+33P3tZ2h4ZEcf44ygDgstkGwel pdw3HTjvTDSWyUCY1NNhdiMqGvDm5nlQIPC0HeyUtjKMDK0GIAE= =j5EO -----END PGP SIGNATURE----- --ac2c4ewsv4bdieh7--