[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] confmgt: Stop adding a space, when there is no option value



commit f29de4b8d2097676f9d2f067c176b38a08362046
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Fri Nov 1 14:30:30 2019 +1000

    confmgt: Stop adding a space, when there is no option value
    
    Fixes bug 32352; bugfix on 0.0.9pre6.
---
 changes/bug32352          | 6 ++++++
 src/lib/confmgt/confmgt.c | 9 ++++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/changes/bug32352 b/changes/bug32352
new file mode 100644
index 000000000..ca93e4efd
--- /dev/null
+++ 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
index 1218a63ae..3fdb630e8 100644
--- 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);
     }
   }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits