From fa0fe45103725c7a78bbcefccf277d6ad131009c Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 22 Jun 2011 15:46:33 +0200 Subject: [PATCH] top: one sanity check endpoint->slot number --- commands/top/top.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/commands/top/top.c b/commands/top/top.c index 0e6d0d246..4f64902ff 100644 --- a/commands/top/top.c +++ b/commands/top/top.c @@ -88,6 +88,7 @@ void parse_file(pid_t pid) unsigned long cycles_hi, cycles_lo; FILE *fp; struct proc *p; + int slot; int i; sprintf(path, "%d/psinfo", pid); @@ -110,7 +111,15 @@ void parse_file(pid_t pid) return; } - p = &proc[SLOT_NR(endpt)]; + slot = SLOT_NR(endpt); + + if(slot < 0 || slot >= nr_total) { + fprintf(stderr, "top: unreasonable endpoint number %d\n", endpt); + fclose(fp); + return; + } + + p = &proc[slot]; if (type == TYPE_TASK) p->p_flags |= IS_TASK; -- 2.44.0