summaryrefslogtreecommitdiff
path: root/lib/libkvm/kvm_file2.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-11-12 14:49:42 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-11-12 14:49:42 +0000
commitd05651980092a954b910c956208c7fa010b260c6 (patch)
tree57f24da5cf129cabdd4c71791ff8e82dae03f2e6 /lib/libkvm/kvm_file2.c
parent0036192e5d3827fece99d6b7cb4e765c0aeb9859 (diff)
Apply format __attribute__ to _kvm_err() and fix the errors that it detects.
Treat failure to KREAD teh pcredd or ucreds to be errors insteading of continuing with bogus data. ok deraadt@ millert@
Diffstat (limited to 'lib/libkvm/kvm_file2.c')
-rw-r--r--lib/libkvm/kvm_file2.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/lib/libkvm/kvm_file2.c b/lib/libkvm/kvm_file2.c
index 45b08dd8669..7e73671a848 100644
--- a/lib/libkvm/kvm_file2.c
+++ b/lib/libkvm/kvm_file2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kvm_file2.c,v 1.29 2013/11/12 05:04:29 deraadt Exp $ */
+/* $OpenBSD: kvm_file2.c,v 1.30 2013/11/12 14:49:41 guenther Exp $ */
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -182,7 +182,7 @@ kvm_getfiles(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
case KERN_FILE_BYFILE:
if (arg != 0) {
_kvm_err(kd, kd->program,
- "%s: invalid argument");
+ "%d: invalid argument", arg);
return (NULL);
}
return (kvm_deadfile_byfile(kd, op, arg, esize, cnt));
@@ -313,7 +313,8 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
p != NULL;
p = LIST_NEXT(&proc, p_list)) {
if (KREAD(kd, (u_long)p, &proc)) {
- _kvm_err(kd, kd->program, "can't read proc at %x", p);
+ _kvm_err(kd, kd->program, "can't read proc at %lx",
+ (u_long)p);
goto cleanup;
}
@@ -337,8 +338,8 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
continue;
if (KREAD(kd, (u_long)proc.p_p, &process)) {
- _kvm_err(kd, kd->program, "can't read process at %x",
- proc.p_p);
+ _kvm_err(kd, kd->program, "can't read process at %lx",
+ (u_long)proc.p_p);
goto cleanup;
}
if (process.ps_flags & PS_EXITING)
@@ -349,21 +350,29 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
else {
if (KREAD(kd, (u_long)process.ps_mainproc, &proc2)) {
_kvm_err(kd, kd->program,
- "can't read proc at %x",
- process.ps_mainproc);
+ "can't read proc at %lx",
+ (u_long)process.ps_mainproc);
goto cleanup;
}
pid = proc2.p_pid;
}
- if (KREAD(kd, (u_long)process.ps_cred, &pcred) == 0)
- KREAD(kd, (u_long)pcred.pc_ucred, &ucred);
+ if (KREAD(kd, (u_long)process.ps_cred, &pcred)) {
+ _kvm_err(kd, kd->program, "can't read pcred at %lx",
+ (u_long)process.ps_cred);
+ goto cleanup;
+ }
+ if (KREAD(kd, (u_long)pcred.pc_ucred, &ucred)) {
+ _kvm_err(kd, kd->program, "can't read ucred at %lx",
+ (u_long)pcred.pc_ucred);
+ goto cleanup;
+ }
process.ps_cred = &pcred;
pcred.pc_ucred = &ucred;
if (KREAD(kd, (u_long)proc.p_fd, &filed0)) {
- _kvm_err(kd, kd->program, "can't read filedesc at %x",
- proc.p_fd);
+ _kvm_err(kd, kd->program, "can't read filedesc at %lx",
+ (u_long)proc.p_fd);
goto cleanup;
}
if ((char *)proc.p_fd + offsetof(struct filedesc0, fd_dfiles)
@@ -440,8 +449,8 @@ kvm_deadfile_byid(kvm_t *kd, int op, int arg, size_t esize, int *cnt)
filed.fd_lastfile >= filed.fd_nfiles ||
filed.fd_freefile > filed.fd_lastfile + 1) {
_kvm_err(kd, kd->program,
- "filedesc corrupted at %x for pid %d",
- proc.p_fd, proc.p_pid);
+ "filedesc corrupted at %lx for pid %d",
+ (u_long)proc.p_fd, proc.p_pid);
goto cleanup;
}