From owner-svn-src-all@freebsd.org Mon May 16 23:29:06 2016 Return-Path: Delivered-To: svn-src-all@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 0B2FEB3E5DD; Mon, 16 May 2016 23:29:06 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 B6E9B1DA0; Mon, 16 May 2016 23:29:05 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u4GNT4ji085904; Mon, 16 May 2016 23:29:04 GMT (envelope-from truckman@FreeBSD.org) Received: (from truckman@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4GNT4Si085903; Mon, 16 May 2016 23:29:04 GMT (envelope-from truckman@FreeBSD.org) Message-Id: <201605162329.u4GNT4Si085903@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: truckman set sender to truckman@FreeBSD.org using -f From: Don Lewis Date: Mon, 16 May 2016 23:29:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299988 - head/usr.sbin/rpc.statd X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 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: Mon, 16 May 2016 23:29:06 -0000 Author: truckman Date: Mon May 16 23:29:04 2016 New Revision: 299988 URL: https://svnweb.freebsd.org/changeset/base/299988 Log: Set ai2 to NULL in in find_host() before the loop and after calling freeaddrinfo() on it to indicate that it doesn't point to a valid addrinfo list. This fixes this Coverity issues: 1006368 Uninitialized pointer read 1018506 Double free 1305590 Resource leak that can be triggered in the hp->hostname[0] != '\0' case. Don't treat a character as a boolean. Fix these Coverity issues: 1009293 Unchecked return value from library 1194246 Wrong size argument by tweaking the status file extend code. Reported by: Coverity CID: 1006368, 1018506, 1305590, 1009293, 1194246 Reviewed by: rmacklem Feedback from: hrs MFC after: 1 week Differential Revision: D6398 Modified: head/usr.sbin/rpc.statd/file.c Modified: head/usr.sbin/rpc.statd/file.c ============================================================================== --- head/usr.sbin/rpc.statd/file.c Mon May 16 23:20:19 2016 (r299987) +++ head/usr.sbin/rpc.statd/file.c Mon May 16 23:29:04 2016 (r299988) @@ -82,6 +82,7 @@ HostInfo *find_host(char *hostname, int struct addrinfo *ai1, *ai2; int i; + ai2 = NULL; if (getaddrinfo(hostname, NULL, NULL, &ai1) != 0) ai1 = NULL; for (i = 0, hp = status_info->hosts; i < status_info->noOfHosts; i++, hp++) @@ -91,7 +92,7 @@ HostInfo *find_host(char *hostname, int result = hp; break; } - if (hp->hostname[0] && + if (hp->hostname[0] != '\0' && getaddrinfo(hp->hostname, NULL, NULL, &ai2) != 0) ai2 = NULL; if (ai1 && ai2) @@ -113,8 +114,10 @@ HostInfo *find_host(char *hostname, int if (result) break; } - if (ai2) + if (ai2) { freeaddrinfo(ai2); + ai2 = NULL; + } if (!spare_slot && !hp->monList && !hp->notifyReqd) spare_slot = hp; } @@ -134,9 +137,8 @@ HostInfo *find_host(char *hostname, int if (desired_size > status_file_len) { /* Extend file by writing 1 byte of junk at the desired end pos */ - lseek(status_fd, desired_size - 1, SEEK_SET); - i = write(status_fd, &i, 1); - if (i < 1) + if (lseek(status_fd, desired_size - 1, SEEK_SET) == -1 || + write(status_fd, "\0", 1) < 0) { syslog(LOG_ERR, "Unable to extend status file"); return (NULL);