ps - Fix longstanding bug in initial populating loop
authorMatthew Dillon <dillon@apollo.backplane.com>
Wed, 16 Feb 2011 00:58:51 +0000 (16:58 -0800)
committerMatthew Dillon <dillon@apollo.backplane.com>
Wed, 16 Feb 2011 00:58:51 +0000 (16:58 -0800)
* Fix the populating loop to not try to load KInfo[nentries],
  overflowing the array.

* Fixes a seg-fault which can occur when the allocated array is right on
  a page boundary.

bin/ps/ps.c

index 1b1f096..e4dc444 100644 (file)
@@ -408,8 +408,8 @@ main(int argc, char **argv)
        if ((KSort = malloc(nentries * sizeof(KINFO *))) == NULL)
                err(1, NULL);
 
-       for (i = nentries; --i >= 0; ++kp) {
-               KInfo[i].ki_proc = kp;
+       for (i = 0; i < nentries; ++i) {
+               KInfo[i].ki_proc = &kp[i];
                KInfo[i].ki_indent = -1;
                KInfo[i].ki_ctailp = &KInfo[i].ki_cbase;
                if (needuser)