From owner-svn-src-head@FreeBSD.ORG Thu Aug 5 18:27:41 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8E64E1065675; Thu, 5 Aug 2010 18:27:41 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 712738FC0A; Thu, 5 Aug 2010 18:27:41 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o75IRfcD069565; Thu, 5 Aug 2010 18:27:41 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o75IRf21069562; Thu, 5 Aug 2010 18:27:41 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201008051827.o75IRf21069562@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Thu, 5 Aug 2010 18:27:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r210876 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 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: Thu, 05 Aug 2010 18:27:41 -0000 Author: pjd Date: Thu Aug 5 18:27:41 2010 New Revision: 210876 URL: http://svn.freebsd.org/changeset/base/210876 Log: Assert that various buffers we are large enough. MFC after: 1 month Modified: head/sbin/hastd/proto_tcp4.c head/sbin/hastd/proto_uds.c Modified: head/sbin/hastd/proto_tcp4.c ============================================================================== --- head/sbin/hastd/proto_tcp4.c Thu Aug 5 18:26:38 2010 (r210875) +++ head/sbin/hastd/proto_tcp4.c Thu Aug 5 18:27:41 2010 (r210876) @@ -156,7 +156,8 @@ tcp4_addr(const char *addr, struct socka size = (size_t)(pp - addr + 1); if (size > sizeof(iporhost)) return (ENAMETOOLONG); - strlcpy(iporhost, addr, size); + if (strlcpy(iporhost, addr, size) >= size) + return (ENAMETOOLONG); } /* Convert string (IP address or host name) to in_addr_t. */ ip = str2ip(iporhost); @@ -420,8 +421,9 @@ sin2str(struct sockaddr_in *sinp, char * ip = ntohl(sinp->sin_addr.s_addr); port = ntohs(sinp->sin_port); - snprintf(addr, size, "tcp4://%u.%u.%u.%u:%u", ((ip >> 24) & 0xff), - ((ip >> 16) & 0xff), ((ip >> 8) & 0xff), (ip & 0xff), port); + PJDLOG_VERIFY(snprintf(addr, size, "tcp4://%u.%u.%u.%u:%u", + ((ip >> 24) & 0xff), ((ip >> 16) & 0xff), ((ip >> 8) & 0xff), + (ip & 0xff), port) < (ssize_t)size); } static bool @@ -459,7 +461,7 @@ tcp4_local_address(const void *ctx, char sinlen = sizeof(sin); if (getsockname(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } sin2str(&sin, addr, size); @@ -477,7 +479,7 @@ tcp4_remote_address(const void *ctx, cha sinlen = sizeof(sin); if (getpeername(tctx->tc_fd, (struct sockaddr *)&sin, &sinlen) < 0) { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } sin2str(&sin, addr, size); Modified: head/sbin/hastd/proto_uds.c ============================================================================== --- head/sbin/hastd/proto_uds.c Thu Aug 5 18:26:38 2010 (r210875) +++ head/sbin/hastd/proto_uds.c Thu Aug 5 18:27:41 2010 (r210876) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include "hast.h" +#include "pjdlog.h" #include "proto_impl.h" #define UDS_CTX_MAGIC 0xd541c @@ -257,15 +258,15 @@ uds_local_address(const void *ctx, char sunlen = sizeof(sun); if (getsockname(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } assert(sun.sun_family == AF_UNIX); if (sun.sun_path[0] == '\0') { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } - snprintf(addr, size, "uds://%s", sun.sun_path); + PJDLOG_VERIFY(snprintf(addr, size, "uds://%s", sun.sun_path) < (ssize_t)size); } static void @@ -281,12 +282,12 @@ uds_remote_address(const void *ctx, char sunlen = sizeof(sun); if (getpeername(uctx->uc_fd, (struct sockaddr *)&sun, &sunlen) < 0) { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } assert(sun.sun_family == AF_UNIX); if (sun.sun_path[0] == '\0') { - strlcpy(addr, "N/A", size); + PJDLOG_VERIFY(strlcpy(addr, "N/A", size) < size); return; } snprintf(addr, size, "uds://%s", sun.sun_path);