From owner-svn-src-head@FreeBSD.ORG Fri Dec 19 06:48:00 2008 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 3B28F1065673; Fri, 19 Dec 2008 06:48:00 +0000 (UTC) (envelope-from marcus@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2A1878FC12; Fri, 19 Dec 2008 06:48:00 +0000 (UTC) (envelope-from marcus@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBJ6m0Uq064264; Fri, 19 Dec 2008 06:48:00 GMT (envelope-from marcus@svn.freebsd.org) Received: (from marcus@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBJ6lxh0064262; Fri, 19 Dec 2008 06:47:59 GMT (envelope-from marcus@svn.freebsd.org) Message-Id: <200812190647.mBJ6lxh0064262@svn.freebsd.org> From: Joe Marcus Clarke Date: Fri, 19 Dec 2008 06:47:59 +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: r186314 - head/lib/libutil 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: Fri, 19 Dec 2008 06:48:00 -0000 Author: marcus (doc,ports committer) Date: Fri Dec 19 06:47:59 2008 New Revision: 186314 URL: http://svn.freebsd.org/changeset/base/186314 Log: Initialize the cntp pointer to 0 prior to doing any work so that callers don't try to iterate through garbage or NULL memory. Additionally, return NULL instead of 0 on error. Reviewed by: peter Approved by: peter Modified: head/lib/libutil/kinfo_getfile.c head/lib/libutil/kinfo_getvmmap.c Modified: head/lib/libutil/kinfo_getfile.c ============================================================================== --- head/lib/libutil/kinfo_getfile.c Fri Dec 19 06:34:57 2008 (r186313) +++ head/lib/libutil/kinfo_getfile.c Fri Dec 19 06:47:59 2008 (r186314) @@ -19,6 +19,7 @@ kinfo_getfile(pid_t pid, int *cntp) char *buf, *bp, *eb; struct kinfo_file *kif, *kp, *kf; + *cntp = 0; len = 0; mib[0] = CTL_KERN; mib[1] = KERN_PROC; @@ -27,15 +28,15 @@ kinfo_getfile(pid_t pid, int *cntp) error = sysctl(mib, 4, NULL, &len, NULL, 0); if (error) - return (0); + return (NULL); len = len * 4 / 3; buf = malloc(len); if (buf == NULL) - return (0); + return (NULL); error = sysctl(mib, 4, buf, &len, NULL, 0); if (error) { free(buf); - return (0); + return (NULL); } /* Pass 1: count items */ cnt = 0; @@ -50,7 +51,7 @@ kinfo_getfile(pid_t pid, int *cntp) kif = calloc(cnt, sizeof(*kif)); if (kif == NULL) { free(buf); - return (0); + return (NULL); } bp = buf; eb = buf + len; Modified: head/lib/libutil/kinfo_getvmmap.c ============================================================================== --- head/lib/libutil/kinfo_getvmmap.c Fri Dec 19 06:34:57 2008 (r186313) +++ head/lib/libutil/kinfo_getvmmap.c Fri Dec 19 06:47:59 2008 (r186314) @@ -19,6 +19,7 @@ kinfo_getvmmap(pid_t pid, int *cntp) char *buf, *bp, *eb; struct kinfo_vmentry *kiv, *kp, *kv; + *cntp = 0; len = 0; mib[0] = CTL_KERN; mib[1] = KERN_PROC; @@ -27,15 +28,15 @@ kinfo_getvmmap(pid_t pid, int *cntp) error = sysctl(mib, 4, NULL, &len, NULL, 0); if (error) - return (0); + return (NULL); len = len * 4 / 3; buf = malloc(len); if (buf == NULL) - return (0); + return (NULL); error = sysctl(mib, 4, buf, &len, NULL, 0); if (error) { free(buf); - return (0); + return (NULL); } /* Pass 1: count items */ cnt = 0; @@ -50,7 +51,7 @@ kinfo_getvmmap(pid_t pid, int *cntp) kiv = calloc(cnt, sizeof(*kiv)); if (kiv == NULL) { free(buf); - return (0); + return (NULL); } bp = buf; eb = buf + len;