Date: Fri, 19 Dec 2008 06:47:59 +0000 (UTC) From: Joe Marcus Clarke <marcus@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r186314 - head/lib/libutil Message-ID: <200812190647.mBJ6lxh0064262@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200812190647.mBJ6lxh0064262>