diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-16 20:10:25 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-02-17 05:55:03 +0100 |
commit | 437116f238d30f1b9d7b19d8d4364ed937817dff (patch) | |
tree | 9d89a39a945edb282565358c2b76da3da7850197 /src/config.c | |
parent | external-tests: update go version (diff) | |
download | wireguard-tools-437116f238d30f1b9d7b19d8d4364ed937817dff.tar.xz wireguard-tools-437116f238d30f1b9d7b19d8d4364ed937817dff.zip |
wg: allow in-line comments
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/config.c b/src/config.c index 0407b36..93c39fa 100644 --- a/src/config.c +++ b/src/config.c @@ -417,25 +417,30 @@ error: bool config_read_line(struct config_ctx *ctx, const char *input) { - size_t len = strlen(input), cleaned_len = 0; - char *line = calloc(len + 1, sizeof(char)); + size_t len, cleaned_len = 0; + char *line, *comment; bool ret = true; + /* This is what strchrnull is for, but that isn't portable. */ + comment = strchr(input, COMMENT_CHAR); + if (comment) + len = comment - input; + else + len = strlen(input); + + line = calloc(len + 1, sizeof(char)); if (!line) { perror("calloc"); ret = false; goto out; } - if (!len) - goto out; + for (size_t i = 0; i < len; ++i) { if (!isspace(input[i])) line[cleaned_len++] = input[i]; } if (!cleaned_len) goto out; - if (line[0] == COMMENT_CHAR) - goto out; ret = process_line(ctx, line); out: free(line); |