X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fconffile.c;h=2f1e235db0270d2abef51cda50367046f180d156;hp=fa0dc6b792da8bb5fc8a6e4f8d461e6556002d39;hb=bc3c8b3496598b6f7a2d0692f3351c3704cb4b9d;hpb=b98ae9df8c4904289c9390288325058b24caa423 diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index fa0dc6b..2f1e235 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -211,7 +211,7 @@ static void conf_parse_line(int trans, char *line, size_t sz) { char *val, *ptr; - size_t i; + size_t i, valsize; size_t j; static char *section = 0; static char *arg = 0; @@ -256,13 +256,14 @@ conf_parse_line(int trans, char *line, size_t sz) val++, j++; if (*val) i = j; - section = malloc(i); + section = malloc(i+1); if (!section) { xlog_warn("conf_parse_line: %d: malloc (%lu) failed", ln, (unsigned long)i); return; } strncpy(section, line, i); + section[i] = '\0'; if (arg) free(arg); @@ -297,23 +298,16 @@ conf_parse_line(int trans, char *line, size_t sz) } line[strcspn (line, " \t=")] = '\0'; val = line + i + 1 + strspn (line + i + 1, " \t"); + valsize = 0; + while (val[valsize++]); - /* Skip trailing comments, if any */ - for (j = 0; j < sz - (val - line); j++) { - if (val[j] == '#' || val[j] == ';') { + /* Skip trailing spaces and comments */ + for (j = 0; j < valsize; j++) { + if (val[j] == '#' || val[j] == ';' || isspace(val[j])) { val[j] = '\0'; break; } } - - /* Skip trailing whitespace, if any */ - for (j--; j > 0; j--) { - if (isspace(val[j])) - val[j] = '\0'; - else - break; - } - /* XXX Perhaps should we not ignore errors? */ conf_set(trans, section, arg, line, val, 0, 0); return;