tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit f29de4b8d2097676f9d2f067c176b38a08362046
parent 5d85c247e8d28726402eaa51eb0e48ea7a1b6d7b
Author: teor <teor@torproject.org>
Date:   Fri,  1 Nov 2019 14:30:30 +1000

confmgt: Stop adding a space, when there is no option value

Fixes bug 32352; bugfix on 0.0.9pre6.

Diffstat:
Achanges/bug32352 | 6++++++
Msrc/lib/confmgt/confmgt.c | 9++++++---
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/changes/bug32352 b/changes/bug32352 @@ -0,0 +1,6 @@ + o Minor bugfixes (config): + - When dumping the config, stop adding a trailing space after the option + name, when there is no option value. This issue only affects options + that accept an empty value or list. (Most options reject empty values, + or delete the entire line from the dumped options.) + Fixes bug 32352; bugfix on 0.0.9pre6. diff --git a/src/lib/confmgt/confmgt.c b/src/lib/confmgt/confmgt.c @@ -1307,9 +1307,10 @@ config_dump(const config_mgr_t *mgr, const void *default_options, */ continue; } - smartlist_add_asprintf(elements, "%s%s %s\n", + int value_exists = line->value && *(line->value); + smartlist_add_asprintf(elements, "%s%s%s%s\n", comment_option ? "# " : "", - line->key, line->value); + line->key, value_exists ? " " : "", line->value); } config_free_lines(assigned); } SMARTLIST_FOREACH_END(mv); @@ -1317,7 +1318,9 @@ config_dump(const config_mgr_t *mgr, const void *default_options, if (fmt->extra) { line = *(config_line_t**)STRUCT_VAR_P(options, fmt->extra->offset); for (; line; line = line->next) { - smartlist_add_asprintf(elements, "%s %s\n", line->key, line->value); + int value_exists = line->value && *(line->value); + smartlist_add_asprintf(elements, "%s%s%s\n", + line->key, value_exists ? " " : "", line->value); } }