Explorar o código

Handle colon in configuration file

If colon was entered as part of value on end of value, it is deleted.
This makes impossible to enter (legal) IPv6 address ending with :: (like
fed0::).

Also when line contains both brace and colon, it is parsed twice (first
as key = value and second as start of section). This is handled by
continue in if section.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Jan Friesse %!s(int64=13) %!d(string=hai) anos
pai
achega
663489d277
Modificáronse 1 ficheiros con 9 adicións e 5 borrados
  1. 9 5
      exec/coroparse.c

+ 9 - 5
exec/coroparse.c

@@ -202,7 +202,7 @@ int coroparse_configparse (const char **error_string)
 	return 0;
 	return 0;
 }
 }
 
 
-static char *remove_whitespace(char *string)
+static char *remove_whitespace(char *string, int remove_colon_and_brace)
 {
 {
 	char *start;
 	char *start;
 	char *end;
 	char *end;
@@ -212,7 +212,7 @@ static char *remove_whitespace(char *string)
 		start++;
 		start++;
 
 
 	end = start+(strlen(start))-1;
 	end = start+(strlen(start))-1;
-	while ((*end == ' ' || *end == '\t' || *end == ':' || *end == '{') && end > start)
+	while ((*end == ' ' || *end == '\t' || (remove_colon_and_brace && (*end == ':' || *end == '{'))) && end > start)
 		end--;
 		end--;
 	if (end != start)
 	if (end != start)
 		*(end+1) = '\0';
 		*(end+1) = '\0';
@@ -274,7 +274,7 @@ static int parse_section(FILE *fp,
 
 
 		/* New section ? */
 		/* New section ? */
 		if ((loc = strchr_rs (line, '{'))) {
 		if ((loc = strchr_rs (line, '{'))) {
-			char *section = remove_whitespace(line);
+			char *section = remove_whitespace(line, 1);
 
 
 			loc--;
 			loc--;
 			*loc = '\0';
 			*loc = '\0';
@@ -291,6 +291,8 @@ static int parse_section(FILE *fp,
 
 
 			if (parse_section(fp, new_keyname, error_string, parser_cb, user_data))
 			if (parse_section(fp, new_keyname, error_string, parser_cb, user_data))
 				return -1;
 				return -1;
+
+			continue ;
 		}
 		}
 
 
 		/* New key/value */
 		/* New key/value */
@@ -299,8 +301,8 @@ static int parse_section(FILE *fp,
 			char *value;
 			char *value;
 
 
 			*(loc-1) = '\0';
 			*(loc-1) = '\0';
-			key = remove_whitespace(line);
-			value = remove_whitespace(loc);
+			key = remove_whitespace(line, 1);
+			value = remove_whitespace(loc, 0);
 
 
 			strcpy(new_keyname, path);
 			strcpy(new_keyname, path);
 			if (strcmp(path, "") != 0) {
 			if (strcmp(path, "") != 0) {
@@ -311,6 +313,8 @@ static int parse_section(FILE *fp,
 			if (!parser_cb(new_keyname, key, value, PARSER_CB_ITEM, error_string, user_data)) {
 			if (!parser_cb(new_keyname, key, value, PARSER_CB_ITEM, error_string, user_data)) {
 				return -1;
 				return -1;
 			}
 			}
+
+			continue ;
 		}
 		}
 
 
 		if (strchr_rs (line, '}')) {
 		if (strchr_rs (line, '}')) {