From owner-svn-src-head@freebsd.org Wed Jul 10 22:40:39 2019 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 C149215E5290 for ; Wed, 10 Jul 2019 22:40:38 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) (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 4CC15759FF for ; Wed, 10 Jul 2019 22:40:38 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-qt1-x830.google.com with SMTP id n11so4298761qtl.5 for ; Wed, 10 Jul 2019 15:40:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RfqsVjdvsLWnDPnqUaU5U8Hp+bcrFaYO8yKMAQ8bzlI=; b=RDGDHR6XiHVLmyQ1WNR1bCCYoAcyzjrEPnC//1Fmg2oEkd9vuLq2P7pkYMufMYkJEm 92HQjQzCVQNjITz2woE97EtH1LQVTjeCgbua8Hg/U7xhgEiXPap7oI1eUCti/ykUPu12 WlHE65+duStmZ//6yuOTdaYSyM+LoRhrcaGEI7RhCogj8nIE/fCi96xRRR7NaXjf59I+ /C4vXlr718hO7yKl1vk6bJjZSTo5IZwQvpIOuHuPG78bTMPe3FVb2xi4DAb49apDAISP IqpuvtUGiflyA3qLCU2GZ0TK/hqAnlDtuwpqGzQbHtRRgYlqB4K9djBI/xCCRDjEbJqK lRzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RfqsVjdvsLWnDPnqUaU5U8Hp+bcrFaYO8yKMAQ8bzlI=; b=SzoE66Vr68jDiHX5bgnk2c3DyTw66kD4F1G499Sr2bapWMlrKGra2BiyXRBHxpMo35 IvG/CPgCWXzU+UWGS9Yf9CLnXto1A0/soXCPLSyUUXeMwzDZIcBCMwr9UcrJ3665IlXA Vh6tnxT3SXtO8/WmRcuBROVugNr98bOgRTiZtzM2nyughhsr3j8iWk9nyq6605CR3z7s 63WEgV/NGauVKLY41mKt+jOKintqHYC1h4RV/ujJMaH352oHadoNGUrhZlNShugtcmH+ qw8inPrH4VEILFQEf7eLH11l7vZ9o2O9UA7OIo2yTRXDffwyO9ESq2kbXdSf2Zd26PBT PQoQ== X-Gm-Message-State: APjAAAUQzP3ZfNbySIIg216EGcnxKCHC/Cr//OcyV4Ac1ohwuPPAL5uo ixQZHCXJrRw5iAwbNIhPKl/aY5oaBV7igyxZ0S0= X-Google-Smtp-Source: APXvYqyx6rFgWia53Pcg9R3t0/nosEAdHrUREYM/sAKaWRF5p8k/OXVztBkT8rPJeD+zaibAirUjgHb+6PrNC4Cq4yw= X-Received: by 2002:ac8:2baa:: with SMTP id m39mr355136qtm.242.1562798436769; Wed, 10 Jul 2019 15:40:36 -0700 (PDT) MIME-Version: 1.0 References: <201907101742.x6AHg4os016752@repo.freebsd.org> <20190710195548.kdftfemj3icarcxo@mutt-hbsd> <20190710151944.0fd94ec3@titan.knownspace> <20190710202218.yc3lcd6tsql3zkyr@mutt-hbsd> <20190710222918.vj4creizlubdzgw3@mutt-hbsd> In-Reply-To: <20190710222918.vj4creizlubdzgw3@mutt-hbsd> From: Warner Losh Date: Wed, 10 Jul 2019 16:40:25 -0600 Message-ID: Subject: Re: svn commit: r349890 - head/contrib/telnet/telnet To: Shawn Webb Cc: Justin Hibbits , Philip Paeps , src-committers , svn-src-all , svn-src-head X-Rspamd-Queue-Id: 4CC15759FF X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.95 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.955,0]; REPLY(-4.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 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: Wed, 10 Jul 2019 22:40:39 -0000 On Wed, Jul 10, 2019 at 4:29 PM Shawn Webb wrote: > 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 > > > > > > ============================================================================== > > > > > --- 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 = strchr((char *)ep->value, ':'); > > > > > > > > > > - gethostname(hbuf, 256); > > > > > - hbuf[256] = '\0'; > > > > > - cp = (char *)malloc(strlen(hbuf) + strlen(cp2) + > > > > > 1); > > > > > - sprintf((char *)cp, "%s%s", hbuf, cp2); > > > > > + gethostname(hbuf, sizeof(hbuf)); > > > > > + hbuf[sizeof(hbuf)-1] = '\0'; > > > > > + unsigned int buflen = strlen(hbuf) + strlen(cp2) + > > > > > 1; > > > > > > > > buflen should be defined with the rest of the variables in the code > > > > block above this one. > > > > > > Agreed. > > > > > > > > > > > > + cp = (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 Any reason to not use asprintf instead of malloc + snprintf? Warner