File s390-tools-sles11sp2-cpuplugd_parse_config.patch of Package s390-tools

Description: cpuplugd: fix config file parsing
Symptom:     Commented lines in the config file might not be ignored and
             trigger a parsing error. Also, invalid variable names might not
             be rejected if they match a correct substring.
Problem:     Comment handling and string matching is broken.
Solution:    Fix comment handling and string matching.
Problem-ID:  74419
---
 cpuplugd/config.c |   16 ++++++++--------
 cpuplugd/info.c   |   13 +++++++------
 2 files changed, 15 insertions(+), 14 deletions(-)

--- a/cpuplugd/config.c
+++ b/cpuplugd/config.c
@@ -111,6 +111,8 @@ static void parse_configline(char *line)
 	size_t len;
 	char temp[strlen(line) + 1];
 
+	if (line[0] == '#')
+		return;
 	for (i = j = 0; line[i] != 0; i++) /* Remove whitespace. */
 		if (!isblank(line[i]) && !isspace(line[i]))
 			temp[j++] = line[i];
@@ -169,14 +171,12 @@ static void parse_configline(char *line)
 	if (check_value("cmm_max", name, rvalue, &cfg.cmm_max))
 		return;
 
-	if (name[0] != '#') {
-		cpuplugd_debug("found the following variable: %s = %s\n",
-			       name, rvalue);
-		if (strlen(name) > MAX_VARNAME)
-			cpuplugd_exit("Variable name too long (max. length is "
-				      "%i chars): %s\n", MAX_VARNAME, name);
-		add_var(name, rvalue);
-	}
+	cpuplugd_debug("found the following variable: %s = %s\n",
+		       name, rvalue);
+	if (strlen(name) > MAX_VARNAME)
+		cpuplugd_exit("Variable name too long (max. length is "
+			      "%i chars): %s\n", MAX_VARNAME, name);
+	add_var(name, rvalue);
 }
 
 /*
--- a/cpuplugd/info.c
+++ b/cpuplugd/info.c
@@ -122,21 +122,22 @@ double get_proc_value(char *procinfo, ch
 {
 	char buf[PROCINFO_LINE];
 	char *proc_offset;
-	unsigned long length;
+	unsigned long proc_length, name_length;
 	double value;
 	int found;
 
 	value = -1;
 	found = 0;
+	name_length = strlen(name);
 	while ((proc_offset = strchr(procinfo, separator))) {
-		length = proc_offset - procinfo;
+		proc_length = proc_offset - procinfo;
 		/*
-		 * proc_read_size() made sure that length < PROCINFO_LINE
+		 * proc_read_size() made sure that proc_length < PROCINFO_LINE
 		 */
-		memcpy(buf, procinfo, length);
-		buf[length] = '\0';
+		memcpy(buf, procinfo, proc_length);
+		buf[proc_length] = '\0';
 		procinfo = proc_offset + 1;
-		if (strncmp(buf, name, length) == 0) {
+		if (strncmp(buf, name, MAX(proc_length, name_length)) == 0) {
 			errno = 0;
 			value = strtod(procinfo, NULL);
 			if (errno)