summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormarcus <marcus@FreeBSD.org>2008-12-19 06:47:59 +0000
committermarcus <marcus@FreeBSD.org>2008-12-19 06:47:59 +0000
commit2368f18ac465224da2b90e0037f39d141448e123 (patch)
treefe6e8c1d4ff300f640bf318bf444c43c3ddc2489 /lib
parentfba34872ecb4a70ea6cebcc3e9c772b8d676df27 (diff)
downloadFreeBSD-src-2368f18ac465224da2b90e0037f39d141448e123.zip
FreeBSD-src-2368f18ac465224da2b90e0037f39d141448e123.tar.gz
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
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/kinfo_getfile.c9
-rw-r--r--lib/libutil/kinfo_getvmmap.c9
2 files changed, 10 insertions, 8 deletions
diff --git a/lib/libutil/kinfo_getfile.c b/lib/libutil/kinfo_getfile.c
index ca0f832..7a7a09e 100644
--- a/lib/libutil/kinfo_getfile.c
+++ b/lib/libutil/kinfo_getfile.c
@@ -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;
diff --git a/lib/libutil/kinfo_getvmmap.c b/lib/libutil/kinfo_getvmmap.c
index 5436108..559182e 100644
--- a/lib/libutil/kinfo_getvmmap.c
+++ b/lib/libutil/kinfo_getvmmap.c
@@ -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;
OpenPOWER on IntegriCloud