summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Utku selen <aliutku.selen@sonyericsson.com>2010-09-30 09:41:56 +0200
committerJohan Redestig <johan.redestig@sonyericsson.com>2010-09-30 09:41:56 +0200
commit44ed630233afb3f334bf6e21f95027a3bf19971e (patch)
tree44850eed13dd166f8c345b75c6d6437eb121c4a3
parent220a991976c5a029a6b8463c10040c322218934b (diff)
downloadextras-44ed630233afb3f334bf6e21f95027a3bf19971e.tar.gz
Fixed buffer overflow in procrank.
If there are more than 256 processes in the system procrank will overflow the procs array. Switched to heap allocation. Change-Id: I05223333d31f669c6ac87577671e301e6d05c682
-rw-r--r--procrank/procrank.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/procrank/procrank.c b/procrank/procrank.c
index 585fddcd..bd5192d2 100644
--- a/procrank/procrank.c
+++ b/procrank/procrank.c
@@ -43,13 +43,11 @@ declare_sort(uss);
int (*compfn)(const void *a, const void *b);
static int order;
-#define MAX_PROCS 256
-
int main(int argc, char *argv[]) {
pm_kernel_t *ker;
pm_process_t *proc;
pid_t *pids;
- struct proc_info *procs[MAX_PROCS];
+ struct proc_info **procs;
size_t num_procs;
char cmdline[256];
int error;
@@ -92,6 +90,12 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
+ procs = malloc(num_procs * sizeof(struct proc_info*));
+ if (!procs) {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
for (i = 0; i < num_procs; i++) {
procs[i] = malloc(sizeof(struct proc_info));
if (!procs[i]) {