X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=support%2Fnfs%2Fconffile.c;h=5015e945691a7c513700c093c0f37b76a2b7532b;hp=b277c2a9813b6cc42a8ae9e346675d958c108ef5;hb=3ce15aeaa66a2f523c6fa92bfe818734bdedfcea;hpb=fd51c0c39017f44ceec4229f86eaa7c8e193ebdc diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index b277c2a..5015e94 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -49,7 +49,9 @@ #include "conffile.h" #include "xlog.h" -static void conf_load_defaults (int); +#pragma GCC visibility push(hidden) + +static void conf_load_defaults(void); static int conf_set(int , char *, char *, char *, char *, int , int ); @@ -211,8 +213,8 @@ static void conf_parse_line(int trans, char *line, size_t sz) { char *val, *ptr; - size_t i; - int j; + size_t i, valsize; + size_t j; static char *section = 0; static char *arg = 0; static int ln = 0; @@ -251,17 +253,19 @@ conf_parse_line(int trans, char *line, size_t sz) } /* Strip off any blanks before ']' */ val = line; + j=0; while (*val && !isblank(*val)) 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); @@ -271,9 +275,9 @@ conf_parse_line(int trans, char *line, size_t sz) if (ptr == NULL) return; line = ++ptr; - while (*ptr && *ptr != '"') + while (*ptr && *ptr != '"' && *ptr != ']') ptr++; - if (*ptr == '\0') { + if (*ptr == '\0' || *ptr == ']') { xlog_warn("config file error: line %d: " "non-matched '\"', ignoring until next section", ln); } else { @@ -296,23 +300,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; @@ -353,7 +350,7 @@ conf_parse(int trans, char *buf, size_t sz) } static void -conf_load_defaults(int tr) +conf_load_defaults(void) { /* No defaults */ return; @@ -412,7 +409,7 @@ conf_reinit(void) trans = conf_begin(); /* Load default configuration values. */ - conf_load_defaults(trans); + conf_load_defaults(); /* Free potential existing configuration. */ if (conf_addr) {