summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2010-02-14 00:17:15 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2010-02-14 00:17:15 +0000
commit6d42db4666854d81ca042ff053a4e33998770f94 (patch)
tree05fd569c888e76bb5a8f045a8f5ac78dbd4382e2
parent45b17beb19783d6d175539e9e6353c1cae72f4bf (diff)
Avoid overflow and wraparound in memory fields by using unsigned
long long arithmetic and formats. Use PTRWIDTH for the column size for various address fields. ok otto@ tedu@
-rw-r--r--bin/ps/keyword.c10
-rw-r--r--bin/ps/print.c18
2 files changed, 14 insertions, 14 deletions
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index e861e3a5d0d..bf475952ee1 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keyword.c,v 1.29 2009/10/27 23:59:22 deraadt Exp $ */
+/* $OpenBSD: keyword.c,v 1.30 2010/02/14 00:17:14 guenther Exp $ */
/* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */
/*-
@@ -102,7 +102,7 @@ VAR var[] = {
{"jobc", "JOBC", NULL, 0, pvar, 4, 0, POFF(p_jobc), INT16, "d"},
{"ktrace", "KTRACE", NULL, 0, pvar, 8, 0, POFF(p_traceflag), INT32, "x"},
/* XXX */
- {"ktracep", "KTRACEP", NULL, 0, pvar, 8, 0, POFF(p_tracep), UINT64, "llx"},
+ {"ktracep", "KTRACEP", NULL, 0, pvar, PTRWIDTH, 0, POFF(p_tracep), UINT64, "llx"},
{"lim", "LIM", NULL, 0, maxrss, 5},
{"login", "LOGIN", NULL, LJUST, logname, MAXLOGNAME},
{"logname", "", "login"},
@@ -119,13 +119,13 @@ VAR var[] = {
{"nswap", "NSWAP", NULL, USER, pvar, 4, 0, POFF(p_uru_nswap), UINT64, "lld"},
{"nvcsw", "NVCSW", NULL, USER, pvar, 5, 0, POFF(p_uru_nvcsw), UINT64, "lld"},
/* XXX */
- {"nwchan", "WCHAN", NULL, 0, pvar, 7, 0, POFF(p_wchan), UINT64, "llx"},
+ {"nwchan", "WCHAN", NULL, 0, pvar, PTRWIDTH, 0, POFF(p_wchan), UINT64, "llx"},
{"oublk", "OUBLK", NULL, USER, pvar, 4, 0, POFF(p_uru_oublock), UINT64, "lld"},
{"oublock", "", "oublk"},
/* XXX */
- {"p_ru", "P_RU", NULL, 0, pvar, 6, 0, POFF(p_ru), UINT64, "llx"},
+ {"p_ru", "P_RU", NULL, 0, pvar, PTRWIDTH, 0, POFF(p_ru), UINT64, "llx"},
/* XXX */
- {"paddr", "PADDR", NULL, 0, pvar, 6, 0, POFF(p_paddr), UINT64, "llx"},
+ {"paddr", "PADDR", NULL, 0, pvar, PTRWIDTH, 0, POFF(p_paddr), UINT64, "llx"},
{"pagein", "PAGEIN", NULL, USER, pagein, 6},
{"pcpu", "", "%cpu"},
{"pending", "", "sig"},
diff --git a/bin/ps/print.c b/bin/ps/print.c
index b8ac1f03f19..f9c37f2337c 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.45 2009/10/27 23:59:22 deraadt Exp $ */
+/* $OpenBSD: print.c,v 1.46 2010/02/14 00:17:14 guenther Exp $ */
/* $NetBSD: print.c,v 1.27 1995/09/29 21:58:12 cgd Exp $ */
/*-
@@ -192,7 +192,7 @@ logname(const struct kinfo_proc2 *kp, VARENT *ve)
(void)printf("%-*s", v->width, "-");
}
-#define pgtok(a) (((a)*getpagesize())/1024)
+#define pgtok(a) (((unsigned long long)(a)*getpagesize())/1024)
void
state(const struct kinfo_proc2 *kp, VARENT *ve)
@@ -452,7 +452,7 @@ vsize(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width,
+ (void)printf("%*llu", v->width,
pgtok(kp->p_vm_dsize + kp->p_vm_ssize + kp->p_vm_tsize));
}
@@ -463,7 +463,7 @@ rssize(const struct kinfo_proc2 *kp, VARENT *ve)
v = ve->var;
/* XXX don't have info about shared */
- (void)printf("%*d", v->width, (kp->p_flag & P_SYSTEM) ? 0 :
+ (void)printf("%*llu", v->width, (kp->p_flag & P_SYSTEM) ? 0 :
pgtok(kp->p_vm_rssize));
}
@@ -473,7 +473,7 @@ p_rssize(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width, (kp->p_flag & P_SYSTEM) ? 0 :
+ (void)printf("%*llu", v->width, (kp->p_flag & P_SYSTEM) ? 0 :
pgtok(kp->p_vm_rssize));
}
@@ -592,7 +592,7 @@ maxrss(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*lld", v->width, kp->p_rlim_rss_cur / 1024);
+ (void)printf("%*llu", v->width, kp->p_rlim_rss_cur / 1024);
}
void
@@ -601,7 +601,7 @@ tsize(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width, pgtok(kp->p_vm_tsize));
+ (void)printf("%*llu", v->width, pgtok(kp->p_vm_tsize));
}
void
@@ -610,7 +610,7 @@ dsize(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width, pgtok(kp->p_vm_dsize));
+ (void)printf("%*llu", v->width, pgtok(kp->p_vm_dsize));
}
void
@@ -619,7 +619,7 @@ ssize(const struct kinfo_proc2 *kp, VARENT *ve)
VAR *v;
v = ve->var;
- (void)printf("%*d", v->width, pgtok(kp->p_vm_ssize));
+ (void)printf("%*llu", v->width, pgtok(kp->p_vm_ssize));
}
/*