File sysstat-fix-segfault-in-read_task_stats.patch of Package sysstat.22705

Index: sysstat-12.0.2/pidstat.c
===================================================================
--- sysstat-12.0.2.orig/pidstat.c
+++ sysstat-12.0.2/pidstat.c
@@ -970,6 +970,16 @@ void read_task_stats(int curr, unsigned
 		return;
 
 	while ((drp = readdir(dir)) != NULL) {
+		
+		// read_task_stats might be called by read_stats
+		// while in the last pid entry, therefore *index
+		// can be greater than pid_nr. In that case, let's
+		// realloc before attempting to write to it later
+		// when read_pid_stats() is called
+		if (*index >= pid_nr) {
+			realloc_pid();
+		}
+
 		if (!isdigit(drp->d_name[0])) {
 			continue;
 		}
@@ -980,9 +990,6 @@ void read_task_stats(int curr, unsigned
 			pst->pid = 0;
 		}
 
-		if (*index >= pid_nr) {
-			realloc_pid();
-		}
 	}
 
 	closedir(dir);
openSUSE Build Service is sponsored by