aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLRN <LRN@140774ce-b5e7-0310-ab8b-a85725594a96>2012-12-10 12:04:19 +0000
committerLRN <LRN@140774ce-b5e7-0310-ab8b-a85725594a96>2012-12-10 12:04:19 +0000
commit5dbc1efe7cb08bad59a6ea819d47bf5cb92608d3 (patch)
tree05182e31aa4d9656b785914057b2f55b8b14cd6d
parent394d95cd92204a625fdd475a268fd445168fef3e (diff)
Fix configuration parsing
* Don't leak strndup'ed lines. * Trim leading whitespace, not just trailing * Do whitespace trimming _before_ discarding commented lines (now # or % does not need to be the first character in the line). . git-svn-id: https://gnunet.org/svn/gnunet@25340 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r--src/util/configuration.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 7d5dc10c10..6f2b3aa44b 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -157,6 +157,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
int allow_inline)
{
char *line;
+ char *line_orig;
size_t line_size;
char *pos;
unsigned int nr;
@@ -175,26 +176,26 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
section = GNUNET_strdup ("");
nr = 0;
r_bytes = 0;
+ line_orig = NULL;
while (r_bytes < size)
{
+ GNUNET_free_non_null (line_orig);
/* fgets-like behaviour on buffer */
to_read = size - r_bytes;
pos = memchr (&mem[r_bytes], '\n', to_read);
if (NULL == pos)
{
- line = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
+ line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read);
r_bytes += line_size;
}
else
{
- line = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
+ line_orig = GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes]));
r_bytes += line_size + 1;
}
+ line = line_orig;
/* increment line number */
nr++;
- /* ignore comments */
- if ( ('#' == line[0]) || ('%' == line[0]) )
- continue;
/* tabs and '\r' are whitespace */
emptyline = GNUNET_YES;
for (i = 0; i < line_size; i++)
@@ -214,6 +215,13 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i]));i--)
line[i] = '\0';
+ /* remove leading whitespace */
+ for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++);
+
+ /* ignore comments */
+ if ( ('#' == line[0]) || ('%' == line[0]) )
+ continue;
+
/* handle special "@INLINE@" directive */
if (0 == strncasecmp (line,
"@INLINE@ ",