From 99cf3f99c02752f8d6d89fe94272454c55285b66 Mon Sep 17 00:00:00 2001 From: Neel Chauhan Date: Tue, 26 Nov 2019 20:57:33 -0500 Subject: [PATCH 1/5] Make control_event_conf_changed() take a config_line_t --- changes/bug31531 | 4 ++++ src/app/config/config.c | 8 +------- src/feature/control/control_events.c | 17 +++++++---------- src/feature/control/control_events.h | 3 ++- 4 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 changes/bug31531 diff --git a/changes/bug31531 b/changes/bug31531 new file mode 100644 index 0000000000..c549c79ecb --- /dev/null +++ b/changes/bug31531 @@ -0,0 +1,4 @@ + o Minor bugfixes (configuration handling): + - Make control_event_conf_changed() take in a config_line_t instead of + a smartlist(k, v, k, v, ...) where keys are followed by values. Fixes + bug 31531; bugfix on 0.2.3.3-alpha. Patch by Neel Chauhan. diff --git a/src/app/config/config.c b/src/app/config/config.c index 34f20c31c8..5ea8cec6a6 100644 --- a/src/app/config/config.c +++ b/src/app/config/config.c @@ -1001,15 +1001,9 @@ set_options(or_options_t *new_val, char **msg) /* Issues a CONF_CHANGED event to notify controller of the change. If Tor is * just starting up then the old_options will be undefined. */ if (old_options && old_options != global_options) { - smartlist_t *elements = smartlist_new(); config_line_t *changes = config_get_changes(get_options_mgr(), old_options, new_val); - for (config_line_t *line = changes; line; line = line->next) { - smartlist_add(elements, line->key); - smartlist_add(elements, line->value); - } - control_event_conf_changed(elements); - smartlist_free(elements); + control_event_conf_changed(changes); config_free_lines(changes); } diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index f88bcfdb9f..02e30f66da 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -38,6 +38,7 @@ #include "core/or/origin_circuit_st.h" #include "lib/evloop/compat_libevent.h" +#include "lib/encoding/confline.h" static void flush_queued_events_cb(mainloop_event_t *event, void *arg); static void control_get_bytes_rw_last_sec(uint64_t *r, uint64_t *w); @@ -1774,23 +1775,19 @@ control_event_guard(const char *nickname, const char *digest, * a smartlist_t containing (key, value, ...) pairs in sequence. * value can be NULL. */ int -control_event_conf_changed(const smartlist_t *elements) +control_event_conf_changed(const config_line_t *elements) { - int i; char *result; smartlist_t *lines; - if (!EVENT_IS_INTERESTING(EVENT_CONF_CHANGED) || - smartlist_len(elements) == 0) { + if (!EVENT_IS_INTERESTING(EVENT_CONF_CHANGED) || !elements) { return 0; } lines = smartlist_new(); - for (i = 0; i < smartlist_len(elements); i += 2) { - char *k = smartlist_get(elements, i); - char *v = smartlist_get(elements, i+1); - if (v == NULL) { - smartlist_add_asprintf(lines, "650-%s", k); + for (const config_line_t *line = elements; line; line = line->next) { + if (line->value == NULL) { + smartlist_add_asprintf(lines, "650-%s", line->key); } else { - smartlist_add_asprintf(lines, "650-%s=%s", k, v); + smartlist_add_asprintf(lines, "650-%s=%s", line->key, line->value); } } result = smartlist_join_strings(lines, "\r\n", 0, NULL); diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index 34986fdb89..b0cf429fe3 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -13,6 +13,7 @@ #define TOR_CONTROL_EVENTS_H #include "core/or/ocirc_event.h" +#include "lib/encoding/confline.h" /** Used to indicate the type of a CIRC_MINOR event passed to the controller. * The various types are defined in control-spec.txt . */ @@ -157,7 +158,7 @@ int control_event_server_error(const char *format, ...) int control_event_guard(const char *nickname, const char *digest, const char *status); -int control_event_conf_changed(const smartlist_t *elements); +int control_event_conf_changed(const config_line_t *elements); int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args); int control_event_signal(uintptr_t signal); From 7572988ea95fe4ae5201509a37ab06a3c3778c6d Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 29 Nov 2019 10:50:09 +1000 Subject: [PATCH 2/5] control: Remove an unnecessary header in control_events.h And replace it with a struct forward declaration. Also, move all the headers in the file before the forward declaration. Cleanup after 31531. --- src/feature/control/control_events.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index b0cf429fe3..3e9192fcc6 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -13,7 +13,9 @@ #define TOR_CONTROL_EVENTS_H #include "core/or/ocirc_event.h" -#include "lib/encoding/confline.h" +#include "core/or/orconn_event.h" + +struct config_line_t; /** Used to indicate the type of a CIRC_MINOR event passed to the controller. * The various types are defined in control-spec.txt . */ @@ -22,8 +24,6 @@ typedef enum circuit_status_minor_event_t { CIRC_MINOR_EVENT_CANNIBALIZED, } circuit_status_minor_event_t; -#include "core/or/orconn_event.h" - /** Used to indicate the type of a stream event passed to the controller. * The various types are defined in control-spec.txt */ typedef enum stream_status_event_t { @@ -158,7 +158,7 @@ int control_event_server_error(const char *format, ...) int control_event_guard(const char *nickname, const char *digest, const char *status); -int control_event_conf_changed(const config_line_t *elements); +int control_event_conf_changed(const struct config_line_t *elements); int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args); int control_event_signal(uintptr_t signal); From 7a69b3aebc2d1aebc6851ac742c20acb574f78ea Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 29 Nov 2019 10:53:32 +1000 Subject: [PATCH 3/5] control: Rename a function variable Cleanup after 31531. --- src/feature/control/control_events.c | 10 +++++----- src/feature/control/control_events.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 02e30f66da..fb3410b898 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1771,19 +1771,19 @@ control_event_guard(const char *nickname, const char *digest, } /** Called when a configuration option changes. This is generally triggered - * by SETCONF requests and RELOAD/SIGHUP signals. The elements is + * by SETCONF requests and RELOAD/SIGHUP signals. The changes are * a smartlist_t containing (key, value, ...) pairs in sequence. - * value can be NULL. */ + * changes can be NULL. */ int -control_event_conf_changed(const config_line_t *elements) +control_event_conf_changed(const config_line_t *changes) { char *result; smartlist_t *lines; - if (!EVENT_IS_INTERESTING(EVENT_CONF_CHANGED) || !elements) { + if (!EVENT_IS_INTERESTING(EVENT_CONF_CHANGED) || !changes) { return 0; } lines = smartlist_new(); - for (const config_line_t *line = elements; line; line = line->next) { + for (const config_line_t *line = changes; line; line = line->next) { if (line->value == NULL) { smartlist_add_asprintf(lines, "650-%s", line->key); } else { diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index 3e9192fcc6..833727a49f 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -158,7 +158,7 @@ int control_event_server_error(const char *format, ...) int control_event_guard(const char *nickname, const char *digest, const char *status); -int control_event_conf_changed(const struct config_line_t *elements); +int control_event_conf_changed(const struct config_line_t *changes); int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args); int control_event_signal(uintptr_t signal); From f8f278f8c43358d5eb1d316008375313ddbe0fee Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 29 Nov 2019 10:54:42 +1000 Subject: [PATCH 4/5] control: Remove an unused function return value Cleanup after 31531. --- src/feature/control/control_events.c | 5 ++--- src/feature/control/control_events.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index fb3410b898..82349bc6a2 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1774,13 +1774,13 @@ control_event_guard(const char *nickname, const char *digest, * by SETCONF requests and RELOAD/SIGHUP signals. The changes are * a smartlist_t containing (key, value, ...) pairs in sequence. * changes can be NULL. */ -int +void control_event_conf_changed(const config_line_t *changes) { char *result; smartlist_t *lines; if (!EVENT_IS_INTERESTING(EVENT_CONF_CHANGED) || !changes) { - return 0; + return; } lines = smartlist_new(); for (const config_line_t *line = changes; line; line = line->next) { @@ -1796,7 +1796,6 @@ control_event_conf_changed(const config_line_t *changes) tor_free(result); SMARTLIST_FOREACH(lines, char *, cp, tor_free(cp)); smartlist_free(lines); - return 0; } /** We just generated a new summary of which countries we've seen clients diff --git a/src/feature/control/control_events.h b/src/feature/control/control_events.h index 833727a49f..edb0e90cd9 100644 --- a/src/feature/control/control_events.h +++ b/src/feature/control/control_events.h @@ -158,7 +158,7 @@ int control_event_server_error(const char *format, ...) int control_event_guard(const char *nickname, const char *digest, const char *status); -int control_event_conf_changed(const struct config_line_t *changes); +void control_event_conf_changed(const struct config_line_t *changes); int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args); int control_event_signal(uintptr_t signal); From 41a3930129cac293e958ccb43bcddf82a9643e29 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 29 Nov 2019 10:55:27 +1000 Subject: [PATCH 5/5] control: Update an outdated function comment Cleanup after 31531. --- src/feature/control/control_events.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/feature/control/control_events.c b/src/feature/control/control_events.c index 82349bc6a2..ea07a896d4 100644 --- a/src/feature/control/control_events.c +++ b/src/feature/control/control_events.c @@ -1772,8 +1772,9 @@ control_event_guard(const char *nickname, const char *digest, /** Called when a configuration option changes. This is generally triggered * by SETCONF requests and RELOAD/SIGHUP signals. The changes are - * a smartlist_t containing (key, value, ...) pairs in sequence. - * changes can be NULL. */ + * a linked list of configuration key-values. + * changes can be NULL, meaning "no changes". + */ void control_event_conf_changed(const config_line_t *changes) {