@cryptotaxi247 / netdata-1 / commits / 989c856c5

Fix sanitizer errors (#16759)

* fix sanitizer errors in logs.c * fix sanitizer errors in rrdlabels.c * cleanup sanitizer exceptions

Costa Tsaousis committed Jan 11, 2024 at 19:57 UTC 989c856c5bd11c5c1c42b587541858ee992a1a5b
4 files changed +10 -33
database/rrdlabels.c
+7 -7
@@ -694,11 +694,6 @@ static RRDLABEL *rrdlabels_find_label_with_key_unsafe(RRDLABELS *labels, RRDLABE
694 // ----------------------------------------------------------------------------
695 // rrdlabels_add()
696
697 -/*
698 - * FIXME: Attribute added because address sanitizer reports an issue when
699 - * running the agent with `-W unittest`.
700 -*/
701 -__attribute__((no_sanitize("address")))
697 static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, const char *value, RRDLABEL_SRC ls)
698 {
699 RRDLABEL *new_label = add_label_name_value(key, value);
@@ -715,10 +710,13 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
710
711 if(*PValue) {
712 new_ls |= RRDLABEL_FLAG_OLD;
713 + *((RRDLABEL_SRC *)PValue) = new_ls;
714 +
715 delete_label(new_label);
716 }
717 else {
718 new_ls |= RRDLABEL_FLAG_NEW;
719 + *((RRDLABEL_SRC *)PValue) = new_ls;
720
721 RRDLABEL *old_label_with_same_key = rrdlabels_find_label_with_key_unsafe(labels, new_label);
722 if (old_label_with_same_key) {
@@ -728,7 +726,6 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
726 }
727
728 labels->version++;
731 - *((RRDLABEL_SRC *)PValue) = new_ls;
729
730 size_t mem_after_judyl = JudyLMemUsed(labels->JudyL);
731 STATS_PLUS_MEMORY(&dictionary_stats_category_rrdlabels, 0, mem_after_judyl - mem_before_judyl, 0);
@@ -1470,9 +1467,12 @@ static int rrdlabels_unittest_double_check()
1467 rrdlabels_add(labels, "key1", "value1", RRDLABEL_SRC_CONFIG);
1468 ret += rrdlabels_unittest_expect_value(labels, "key1", "value1", RRDLABEL_FLAG_NEW);
1469
1473 - rrdlabels_add(labels, "key1", "value2", RRDLABEL_SRC_CONFIG);
1470 + rrdlabels_add(labels, "key1", "value2", RRDLABEL_SRC_K8S);
1471 ret += !rrdlabels_unittest_expect_value(labels, "key1", "value2", RRDLABEL_FLAG_OLD);
1472
1473 + rrdlabels_add(labels, "key1", "value3", RRDLABEL_SRC_ACLK);
1474 + ret += !rrdlabels_unittest_expect_value(labels, "key1", "value3", RRDLABEL_FLAG_OLD);
1475 +
1476 ret += (rrdlabels_entries(labels) != 1);
1477
1478 rrdlabels_destroy(labels);
libnetdata/buffer/buffer.h
-5
@@ -279,11 +279,6 @@ static inline void buffer_memcat(BUFFER *wb, const void *mem, size_t bytes) {
279 buffer_overflow_check(wb);
280 }
281
282 -/*
283 - * FIXME: Attribute added because address sanitizer reports a log-related
284 - * issue when running the agent with `-W unittest`.
285 -*/
286 -__attribute__((no_sanitize("address")))
282 static inline void buffer_json_strcat(BUFFER *wb, const char *txt)
283 {
284 if(unlikely(!txt || !*txt)) return;
libnetdata/dictionary/dictionary.c
+2
@@ -3803,6 +3803,8 @@ int dictionary_unittest(size_t entries) {
3803 errors += dictionary_unittest_threads();
3804 errors += dictionary_unittest_view_threads();
3805
3806 + cleanup_destroyed_dictionaries();
3807 +
3808 fprintf(stderr, "\n%zu errors found\n", errors);
3809 return errors ? 1 : 0;
3810 }
libnetdata/log/log.c
+1 -21
@@ -1576,11 +1576,6 @@ static void priority_annotator(BUFFER *wb, const char *key, struct log_field *lf
1576 buffer_strcat(wb, nd_log_id2priority(pri));
1577 }
1578
1579 -/*
1580 - * FIXME: Attribute added because address sanitizer reports a log-related
1581 - * issue when running the agent with `-W unittest`.
1582 -*/
1583 -__attribute__((no_sanitize("address")))
1579 static bool needs_quotes_for_logfmt(const char *s)
1580 {
1581 static bool safe_for_logfmt[256] = {
@@ -1613,11 +1608,6 @@ static bool needs_quotes_for_logfmt(const char *s)
1608 return false;
1609 }
1610
1616 -/*
1617 - * FIXME: Attribute added because address sanitizer reports a log-related
1618 - * issue when running the agent with `-W unittest`.
1619 -*/
1620 -__attribute__((no_sanitize("address")))
1611 static void string_to_logfmt(BUFFER *wb, const char *s)
1612 {
1613 bool spaces = needs_quotes_for_logfmt(s);
@@ -1631,11 +1621,6 @@ static void string_to_logfmt(BUFFER *wb, const char *s)
1621 buffer_fast_strcat(wb, "\"", 1);
1622 }
1623
1634 -/*
1635 - * FIXME: Attribute added because address sanitizer reports a log-related
1636 - * issue when running the agent with `-W unittest`.
1637 -*/
1638 -__attribute__((no_sanitize("address")))
1624 static void nd_logger_logfmt(BUFFER *wb, struct log_field *fields, size_t fields_max)
1625 {
1626
@@ -2170,8 +2155,8 @@ static void nd_logger(const char *file, const char *function, const unsigned lon
2155 if(likely(!thread_log_fields[NDF_TID].entry.set))
2156 thread_log_fields[NDF_TID].entry = ND_LOG_FIELD_U64(NDF_TID, gettid());
2157
2158 + char os_threadname[NETDATA_THREAD_NAME_MAX + 1];
2159 if(likely(!thread_log_fields[NDF_THREAD_TAG].entry.set)) {
2174 - char os_threadname[NETDATA_THREAD_NAME_MAX + 1];
2160 const char *thread_tag = netdata_thread_tag();
2161 if(!netdata_thread_tag_exists()) {
2162 if (!netdata_thread_tag_exists()) {
@@ -2260,11 +2245,6 @@ static ND_LOG_SOURCES nd_log_validate_source(ND_LOG_SOURCES source) {
2245 // ----------------------------------------------------------------------------
2246 // public API for loggers
2247
2263 -/*
2264 - * FIXME: Attribute added because address sanitizer reports a log-related
2265 - * issue when running the agent with `-W unittest`.
2266 -*/
2267 -__attribute__((no_sanitize("address")))
2248 void netdata_logger(ND_LOG_SOURCES source, ND_LOG_FIELD_PRIORITY priority, const char *file, const char *function, unsigned long line, const char *fmt, ... )
2249 {
2250 int saved_errno = errno;