]> Zhao Yanbai Git Server - minix.git/commitdiff
top: one sanity check endpoint->slot number
authorBen Gras <ben@minix3.org>
Wed, 22 Jun 2011 13:46:33 +0000 (15:46 +0200)
committerBen Gras <ben@minix3.org>
Wed, 22 Jun 2011 13:49:42 +0000 (15:49 +0200)
commands/top/top.c

index 0e6d0d246eec4916bdfd5871a61b07730dc57d0c..4f64902ff00120ba40c910f87d8b8455ba9ce749 100644 (file)
@@ -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;