Kaynağa Gözat

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>
(backport from needle)
Jan Friesse 13 yıl önce
ebeveyn
işleme
c04af91ada
1 değiştirilmiş dosya ile 9 ekleme ve 5 silme
  1. 9 5
      exec/coroparse.c

+ 9 - 5
exec/coroparse.c

@@ -87,12 +87,12 @@ static int aisparser_readconfig (struct objdb_iface_ver0 *objdb,
 }
 
 
-static char *remove_whitespace(char *string)
+static char *remove_whitespace(char *string, int remove_colon_and_brace)
 {
 	char *start = string+strspn(string, " \t");
 	char *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--;
 	if (end != start)
 		*(end+1) = '\0';
@@ -157,7 +157,7 @@ static int parse_section(FILE *fp,
 		/* New section ? */
 		if ((loc = strchr_rs (line, '{'))) {
 			hdb_handle_t new_parent;
-			char *section = remove_whitespace(line);
+			char *section = remove_whitespace(line, 1);
 
 			loc--;
 			*loc = '\0';
@@ -171,6 +171,8 @@ static int parse_section(FILE *fp,
 					      section, strlen (section));
 			if (parse_section(fp, objdb, new_parent, error_string, parser_check_item_call))
 				return -1;
+
+			continue ;
 		}
 
 		/* New key/value */
@@ -179,8 +181,8 @@ static int parse_section(FILE *fp,
 			char *value;
 
 			*(loc-1) = '\0';
-			key = remove_whitespace(line);
-			value = remove_whitespace(loc);
+			key = remove_whitespace(line, 1);
+			value = remove_whitespace(loc, 0);
 			if (parser_check_item_call) {
 				if (!parser_check_item_call(objdb, parent_handle, PCHECK_ADD_ITEM,
 				    key, error_string))
@@ -188,6 +190,8 @@ static int parse_section(FILE *fp,
 			}
 			objdb->object_key_create_typed (parent_handle, key,
 				value, strlen (value) + 1, OBJDB_VALUETYPE_STRING);
+
+			continue ;
 		}
 
 		if (strchr_rs (line, '}')) {