summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominique.leuenberger <dominique.leuenberger@c587cffe-e639-0410-9787-d7902ae8ed56>2009-09-25 11:25:23 +0000
committerdominique.leuenberger <dominique.leuenberger@c587cffe-e639-0410-9787-d7902ae8ed56>2009-09-25 11:25:23 +0000
commit0d848aa8d9835a02f7f25faf1d30b2b7fca81b69 (patch)
tree0c31556bd04757f7d864905a9d4f071f215c6e3c
parent48244c68ef04b96322d020f07d1e8214e89725bd (diff)
downloadlibproxy-git-0d848aa8d9835a02f7f25faf1d30b2b7fca81b69.tar.gz
config_file: ignore empty lines - avoid invalid free calls
-rw-r--r--src/lib/config_file.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/src/lib/config_file.c b/src/lib/config_file.c
index 063844d..d73ca41 100644
--- a/src/lib/config_file.c
+++ b/src/lib/config_file.c
@@ -53,38 +53,37 @@ px_config_file_new(char *filename)
pxStrDict *current = (pxStrDict *) px_strdict_get(self->sections, PX_CONFIG_FILE_DEFAULT_SECTION);
/* Parse our file */
- for (char *line=NULL ; (line = px_readline(fd, NULL, 0)) ; px_free(line))
- {
- /* Strip */
- char *tmp = px_strstrip(line);
- px_free(line); line = tmp;
-
- /* Check for comment and/or empty line */
- if (*line == '#' || !strcmp(line, "")) continue;
-
- /* If we have a new section */
- if (*line == '[' || line[strlen(line)-1] == ']')
+ for (char *line=NULL ; (line = px_readline(fd, NULL, 0)) ; px_free(line) )
+ {
+ if (*line)
{
- /* Get just the section name */
- memmove(line, line+1, strlen(line)-1);
- line[strlen(line)-2] = '\0';
-
- if (px_strdict_get(self->sections, line))
- current = (pxStrDict *) px_strdict_get(self->sections, line);
- else
- px_strdict_set(self->sections, line, px_strdict_new(free));
- }
-
- /* If this is a key/val line, get the key/val. */
- else if ((tmp = strchr(line, '=')) && tmp[1])
- {
- *tmp = '\0';
- char *key = px_strstrip(line);
- px_strdict_set(current, key, px_strstrip(tmp+1));
- px_free(key);
+ /* Strip */
+ char *tmp = px_strstrip(line);
+ px_free(line); line = tmp;
+ /* Check for comment and/or empty line */
+ if (*line == '#' || !strcmp(line, "")) continue;
+ /* If we have a new section */
+ if (*line == '[' || line[strlen(line)-1] == ']')
+ {
+ /* Get just the section name */
+ memmove(line, line+1, strlen(line)-1);
+ line[strlen(line)-2] = '\0';
+ if (px_strdict_get(self->sections, line))
+ current = (pxStrDict *) px_strdict_get(self->sections, line);
+ else
+ px_strdict_set(self->sections, line, px_strdict_new(free));
+ }
+
+ /* If this is a key/val line, get the key/val. */
+ else if ((tmp = strchr(line, '=')) && tmp[1])
+ {
+ *tmp = '\0';
+ char *key = px_strstrip(line);
+ px_strdict_set(current, key, px_strstrip(tmp+1));
+ px_free(key);
+ }
}
}
-
close(fd);
return self;
}