File powerpc-utils-lparstat_Fix_segfault_when_parsing_proc_interrupts.patch of Package powerpc-utils.4891

commit 3c3a53825248e1ef52ee203c968f643c26820cc5
Author: John Allen <jallen@linux.vnet.ibm.com>
Date:   Tue Aug 23 11:23:31 2016 -0400

    lparstat: Fix segfault when parsing /proc/interrupts
    
    Fix a bug where we hit a segfault running 'lparstat -i' on machines with a
    large number of cpus. The 'SPU' line in proc interrupts would exceed the
    512B allocated and we would subsequently walk off the end of the array
    when we attempt to parse the line. This solution uses getline instead of
    fgets in order to easily handle lines of arbitrary length.
    
    Signed-off-by: John Allen <jallen@linux.vnet.ibm.com>

diff --git a/src/lparstat.c b/src/lparstat.c
index bd4ff58..200fced 100644
--- a/src/lparstat.c
+++ b/src/lparstat.c
@@ -203,7 +203,8 @@ int parse_lparcfg()
 int parse_proc_ints()
 {
 	FILE *f;
-	char line[512];
+	char *line;
+	size_t n = 0;
 	char *value;
 	struct sysentry *se;
 	long long int phint = 0;
@@ -214,7 +215,7 @@ int parse_proc_ints()
 		return -1;
 	}
 
-	while (fgets(line, 512, f) != NULL) {
+	while (getline(&line, &n, f) != -1) {
 		/* we just need the SPU line */
 		if (line[0] != 'S' || line[1] != 'P' || line[2] != 'U')
 			continue;
@@ -224,8 +225,11 @@ int parse_proc_ints()
 			v = atoi(value);
 			phint += v;
 		}
+
+		break;
 	}
 
+	free(line);
 	fclose(f);
 
 	se = get_sysentry("phint");
openSUSE Build Service is sponsored by