From owner-svn-src-head@freebsd.org Wed Sep 2 16:50:50 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 49A839C9FA7; Wed, 2 Sep 2015 16:50:50 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (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 381AFA1; Wed, 2 Sep 2015 16:50:50 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t82Goock015512; Wed, 2 Sep 2015 16:50:50 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t82GooQb015511; Wed, 2 Sep 2015 16:50:50 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201509021650.t82GooQb015511@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Wed, 2 Sep 2015 16:50:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287404 - head/lib/libc/net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 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, 02 Sep 2015 16:50:50 -0000 Author: hrs Date: Wed Sep 2 16:50:49 2015 New Revision: 287404 URL: https://svnweb.freebsd.org/changeset/base/287404 Log: - snprintf() returns at most size-1 of the chars printed into the buffer. (n == hostlen) also means the buffer length was too short. - Use sdl->sdl_data only when (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) to prevent redundant output. Modified: head/lib/libc/net/getnameinfo.c Modified: head/lib/libc/net/getnameinfo.c ============================================================================== --- head/lib/libc/net/getnameinfo.c Wed Sep 2 16:48:03 2015 (r287403) +++ head/lib/libc/net/getnameinfo.c Wed Sep 2 16:50:49 2015 (r287404) @@ -394,26 +394,22 @@ getnameinfo_link(const struct sockaddr * if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 && sdl->sdl_slen == 0) { n = snprintf(host, hostlen, "link#%d", sdl->sdl_index); - if (n > hostlen) { + if (n >= hostlen) { *host = '\0'; return (EAI_MEMORY); } return (0); } - if (sdl->sdl_nlen > 0) { - if (sdl->sdl_nlen + 1 > hostlen) { + if (sdl->sdl_nlen > 0 && sdl->sdl_alen == 0) { + n = sdl->sdl_nlen; + if (n >= hostlen) { *host = '\0'; return (EAI_MEMORY); } memcpy(host, sdl->sdl_data, sdl->sdl_nlen); - n = sdl->sdl_nlen; - host += n; - if (sdl->sdl_alen > 0) { - *host++ = ':'; - n++; - } - hostlen -= n; + host[n] = '\0'; + return (0); } switch (sdl->sdl_type) {