diff options
author | teor <teor@torproject.org> | 2019-09-26 13:37:06 +1000 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-09-30 22:05:00 +1000 |
commit | db329522ef6f0d0971111cbd07f35d54e0c7eced (patch) | |
tree | 2050fd94481605344e1e58d77535f56575b20bf7 | |
parent | 25c5322dfe228178391b37fffd3333abdf57baa5 (diff) | |
download | tor-db329522ef6f0d0971111cbd07f35d54e0c7eced.tar.gz tor-db329522ef6f0d0971111cbd07f35d54e0c7eced.zip |
log: When initialising log domain masks, only set known log domains
And add a runtime test that checks for unknown domains and flags.
Fixes bug 31854; bugfix on 0.2.1.1-alpha.
-rw-r--r-- | changes/bug31854 | 3 | ||||
-rw-r--r-- | src/lib/log/log.c | 12 | ||||
-rw-r--r-- | src/test/test_options.c | 6 |
3 files changed, 14 insertions, 7 deletions
diff --git a/changes/bug31854 b/changes/bug31854 new file mode 100644 index 0000000000..692a192fd9 --- /dev/null +++ b/changes/bug31854 @@ -0,0 +1,3 @@ + o Minor bugfixes (logging): + - When initialising log domain masks, only set known log domains. + Fixes bug 31854; bugfix on 0.2.1.1-alpha. diff --git a/src/lib/log/log.c b/src/lib/log/log.c index db4f154418..7c18bea0d9 100644 --- a/src/lib/log/log.c +++ b/src/lib/log/log.c @@ -628,6 +628,10 @@ void tor_log(int severity, log_domain_mask_t domain, const char *format, ...) { va_list ap; + + /* check that domain is composed of known domains and flags */ + raw_assert((domain & (LD_ALL_DOMAINS|LD_ALL_FLAGS)) == domain); + if (severity > log_global_min_severity_) return; va_start(ap,format); @@ -927,7 +931,7 @@ set_log_severity_config(int loglevelMin, int loglevelMax, raw_assert(loglevelMax >= LOG_ERR && loglevelMax <= LOG_DEBUG); memset(severity_out, 0, sizeof(log_severity_list_t)); for (i = loglevelMin; i >= loglevelMax; --i) { - severity_out->masks[SEVERITY_MASK_IDX(i)] = ~0u; + severity_out->masks[SEVERITY_MASK_IDX(i)] = LD_ALL_DOMAINS; } } @@ -1421,7 +1425,7 @@ parse_log_severity_config(const char **cfg_ptr, const char *dash, *space; char *sev_lo, *sev_hi; int low, high, i; - log_domain_mask_t domains = ~0u; + log_domain_mask_t domains = LD_ALL_DOMAINS; if (*cfg == '[') { int err = 0; @@ -1439,7 +1443,7 @@ parse_log_severity_config(const char **cfg_ptr, tor_free(domains_str); SMARTLIST_FOREACH_BEGIN(domains_list, const char *, domain) { if (!strcmp(domain, "*")) { - domains = ~0u; + domains = LD_ALL_DOMAINS; } else { log_domain_mask_t d; int negate=0; @@ -1535,7 +1539,7 @@ switch_logs_debug(void) LOCK_LOGS(); for (lf = logfiles; lf; lf=lf->next) { for (i = LOG_DEBUG; i >= LOG_ERR; --i) - lf->severities->masks[SEVERITY_MASK_IDX(i)] = ~0u; + lf->severities->masks[SEVERITY_MASK_IDX(i)] = LD_ALL_DOMAINS; } log_global_min_severity_ = get_min_log_level(); UNLOCK_LOGS(); diff --git a/src/test/test_options.c b/src/test/test_options.c index b3654ede7d..9eb5a43924 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -54,9 +54,9 @@ setup_log_callback(void) { log_severity_list_t lst; memset(&lst, 0, sizeof(lst)); - lst.masks[SEVERITY_MASK_IDX(LOG_ERR)] = ~0; - lst.masks[SEVERITY_MASK_IDX(LOG_WARN)] = ~0; - lst.masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = ~0; + lst.masks[SEVERITY_MASK_IDX(LOG_ERR)] = LD_ALL_DOMAINS; + lst.masks[SEVERITY_MASK_IDX(LOG_WARN)] = LD_ALL_DOMAINS; + lst.masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = LD_ALL_DOMAINS; add_callback_log(&lst, log_cback); mark_logs_temp(); } |