diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-11-12 14:49:42 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-11-12 14:49:42 +0000 |
commit | d05651980092a954b910c956208c7fa010b260c6 (patch) | |
tree | 57f24da5cf129cabdd4c71791ff8e82dae03f2e6 | |
parent | 0036192e5d3827fece99d6b7cb4e765c0aeb9859 (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@
-rw-r--r-- | lib/libkvm/kvm_file2.c | 35 | ||||
-rw-r--r-- | lib/libkvm/kvm_private.h | 5 | ||||
-rw-r--r-- | lib/libkvm/kvm_proc2.c | 60 |
3 files changed, 57 insertions, 43 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; } diff --git a/lib/libkvm/kvm_private.h b/lib/libkvm/kvm_private.h index 409bace43ad..e6718659f28 100644 --- a/lib/libkvm/kvm_private.h +++ b/lib/libkvm/kvm_private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_private.h,v 1.18 2013/10/22 16:40:27 guenther Exp $ */ +/* $OpenBSD: kvm_private.h,v 1.19 2013/11/12 14:49:41 guenther Exp $ */ /* $NetBSD: kvm_private.h,v 1.7 1996/05/05 04:32:15 gwr Exp $ */ /*- @@ -90,7 +90,8 @@ struct __kvm { /* * Functions used internally by kvm, but across kvm modules. */ -void _kvm_err(kvm_t *kd, const char *program, const char *fmt, ...); +void _kvm_err(kvm_t *kd, const char *program, const char *fmt, ...) + __attribute__((__format__ (printf, 3, 4))); int _kvm_dump_mkheader(kvm_t *kd_live, kvm_t *kd_dump); void _kvm_freevtop(kvm_t *); int _kvm_initvtop(kvm_t *); diff --git a/lib/libkvm/kvm_proc2.c b/lib/libkvm/kvm_proc2.c index 87e024e9440..4a9604e5dc6 100644 --- a/lib/libkvm/kvm_proc2.c +++ b/lib/libkvm/kvm_proc2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc2.c,v 1.16 2013/03/20 14:46:45 deraadt Exp $ */ +/* $OpenBSD: kvm_proc2.c,v 1.17 2013/11/12 14:49:41 guenther Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -126,17 +126,18 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, for (; cnt < maxcnt && 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); return (-1); } 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); return (-1); } if (KREAD(kd, (u_long)process.ps_cred, &pcred)) { - _kvm_err(kd, kd->program, "can't read pcred at %x", - process.ps_cred); + _kvm_err(kd, kd->program, "can't read pcred at %lx", + (u_long)process.ps_cred); return (-1); } if ((proc.p_flag & P_THREAD) == 0) @@ -144,44 +145,44 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, 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); return (-1); } process_pid = proc2.p_pid; } if (KREAD(kd, (u_long)pcred.pc_ucred, &ucred)) { - _kvm_err(kd, kd->program, "can't read ucred at %x", - pcred.pc_ucred); + _kvm_err(kd, kd->program, "can't read ucred at %lx", + (u_long)pcred.pc_ucred); return (-1); } if (KREAD(kd, (u_long)process.ps_pgrp, &pgrp)) { - _kvm_err(kd, kd->program, "can't read pgrp at %x", - process.ps_pgrp); + _kvm_err(kd, kd->program, "can't read pgrp at %lx", + (u_long)process.ps_pgrp); return (-1); } if (KREAD(kd, (u_long)pgrp.pg_session, &sess)) { - _kvm_err(kd, kd->program, "can't read session at %x", - pgrp.pg_session); + _kvm_err(kd, kd->program, "can't read session at %lx", + (u_long)pgrp.pg_session); return (-1); } if ((process.ps_flags & PS_CONTROLT) && sess.s_ttyp != NULL && KREAD(kd, (u_long)sess.s_ttyp, &tty)) { - _kvm_err(kd, kd->program, - "can't read tty at %x", sess.s_ttyp); + _kvm_err(kd, kd->program, "can't read tty at %lx", + (u_long)sess.s_ttyp); return (-1); } if (process.ps_pptr) { if (KREAD(kd, (u_long)process.ps_pptr, &process2)) { _kvm_err(kd, kd->program, - "can't read process at %x", - process.ps_pptr); + "can't read process at %lx", + (u_long)process.ps_pptr); return (-1); } if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) { _kvm_err(kd, kd->program, - "can't read proc at %x", - process2.ps_mainproc); + "can't read proc at %lx", + (u_long)process2.ps_mainproc); return (-1); } parent_pid = proc2.p_pid; @@ -191,13 +192,14 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, if (sess.s_leader) { if (KREAD(kd, (u_long)sess.s_leader, &process2)) { _kvm_err(kd, kd->program, - "can't read proc at %x", sess.s_leader); + "can't read proc at %lx", + (u_long)sess.s_leader); return (-1); } if (KREAD(kd, (u_long)process2.ps_mainproc, &proc2)) { _kvm_err(kd, kd->program, - "can't read proc at %x", - process2.ps_mainproc); + "can't read proc at %lx", + (u_long)process2.ps_mainproc); return (-1); } leader_pid = proc2.p_pid; @@ -206,8 +208,9 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, leader_pid = 0; if (proc.p_sigacts) { if (KREAD(kd, (u_long)proc.p_sigacts, &sa)) { - _kvm_err(kd, kd->program, "can't read sigacts at %x", - proc.p_sigacts); + _kvm_err(kd, kd->program, + "can't read sigacts at %lx", + (u_long)proc.p_sigacts); return (-1); } sap = &sa; @@ -302,8 +305,8 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, tty.t_pgrp != process.ps_pgrp && KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) { _kvm_err(kd, kd->program, - "can't read tpgrp at &x", - tty.t_pgrp); + "can't read tpgrp at %lx", + (u_long)tty.t_pgrp); return (-1); } kp.p_tpgid = tty.t_pgrp ? pgrp.pg_id : -1; @@ -334,7 +337,8 @@ kvm_proclist(kvm_t *kd, int op, int arg, struct proc *p, tty.t_pgrp != process.ps_pgrp && KREAD(kd, (u_long)tty.t_pgrp, &pgrp)) { _kvm_err(kd, kd->program, - "can't read tpgrp at &x", tty.t_pgrp); + "can't read tpgrp at %lx", + (u_long)tty.t_pgrp); return (-1); } kp.p_tpgid = tty.t_pgrp ? pgrp.pg_id : -1; |