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

[tor-commits] [tor/master] log: When initialising log domain masks, only set known log domains



commit db329522ef6f0d0971111cbd07f35d54e0c7eced
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Thu Sep 26 13:37:06 2019 +1000

    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.
---
 changes/bug31854        |  3 +++
 src/lib/log/log.c       | 12 ++++++++----
 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 000000000..692a192fd
--- /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 db4f15441..7c18bea0d 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 b3654ede7..9eb5a4392 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();
 }



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