Skip to content

Commit

Permalink
Fix sanitizer errors (netdata#16759)
Browse files Browse the repository at this point in the history
* fix sanitizer errors in logs.c

* fix sanitizer errors in rrdlabels.c

* cleanup sanitizer exceptions
  • Loading branch information
ktsaou committed Jan 11, 2024
1 parent 2165279 commit 989c856
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
14 changes: 7 additions & 7 deletions database/rrdlabels.c
Expand Up @@ -694,11 +694,6 @@ static RRDLABEL *rrdlabels_find_label_with_key_unsafe(RRDLABELS *labels, RRDLABE
// ----------------------------------------------------------------------------
// rrdlabels_add()

/*
* FIXME: Attribute added because address sanitizer reports an issue when
* running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, const char *value, RRDLABEL_SRC ls)
{
RRDLABEL *new_label = add_label_name_value(key, value);
Expand All @@ -715,10 +710,13 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con

if(*PValue) {
new_ls |= RRDLABEL_FLAG_OLD;
*((RRDLABEL_SRC *)PValue) = new_ls;

delete_label(new_label);
}
else {
new_ls |= RRDLABEL_FLAG_NEW;
*((RRDLABEL_SRC *)PValue) = new_ls;

RRDLABEL *old_label_with_same_key = rrdlabels_find_label_with_key_unsafe(labels, new_label);
if (old_label_with_same_key) {
Expand All @@ -728,7 +726,6 @@ static void labels_add_already_sanitized(RRDLABELS *labels, const char *key, con
}

labels->version++;
*((RRDLABEL_SRC *)PValue) = new_ls;

size_t mem_after_judyl = JudyLMemUsed(labels->JudyL);
STATS_PLUS_MEMORY(&dictionary_stats_category_rrdlabels, 0, mem_after_judyl - mem_before_judyl, 0);
Expand Down Expand Up @@ -1470,9 +1467,12 @@ static int rrdlabels_unittest_double_check()
rrdlabels_add(labels, "key1", "value1", RRDLABEL_SRC_CONFIG);
ret += rrdlabels_unittest_expect_value(labels, "key1", "value1", RRDLABEL_FLAG_NEW);

rrdlabels_add(labels, "key1", "value2", RRDLABEL_SRC_CONFIG);
rrdlabels_add(labels, "key1", "value2", RRDLABEL_SRC_K8S);
ret += !rrdlabels_unittest_expect_value(labels, "key1", "value2", RRDLABEL_FLAG_OLD);

rrdlabels_add(labels, "key1", "value3", RRDLABEL_SRC_ACLK);
ret += !rrdlabels_unittest_expect_value(labels, "key1", "value3", RRDLABEL_FLAG_OLD);

ret += (rrdlabels_entries(labels) != 1);

rrdlabels_destroy(labels);
Expand Down
5 changes: 0 additions & 5 deletions libnetdata/buffer/buffer.h
Expand Up @@ -279,11 +279,6 @@ static inline void buffer_memcat(BUFFER *wb, const void *mem, size_t bytes) {
buffer_overflow_check(wb);
}

/*
* FIXME: Attribute added because address sanitizer reports a log-related
* issue when running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
static inline void buffer_json_strcat(BUFFER *wb, const char *txt)
{
if(unlikely(!txt || !*txt)) return;
Expand Down
2 changes: 2 additions & 0 deletions libnetdata/dictionary/dictionary.c
Expand Up @@ -3803,6 +3803,8 @@ int dictionary_unittest(size_t entries) {
errors += dictionary_unittest_threads();
errors += dictionary_unittest_view_threads();

cleanup_destroyed_dictionaries();

fprintf(stderr, "\n%zu errors found\n", errors);
return errors ? 1 : 0;
}
22 changes: 1 addition & 21 deletions libnetdata/log/log.c
Expand Up @@ -1576,11 +1576,6 @@ static void priority_annotator(BUFFER *wb, const char *key, struct log_field *lf
buffer_strcat(wb, nd_log_id2priority(pri));
}

/*
* FIXME: Attribute added because address sanitizer reports a log-related
* issue when running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
static bool needs_quotes_for_logfmt(const char *s)
{
static bool safe_for_logfmt[256] = {
Expand Down Expand Up @@ -1613,11 +1608,6 @@ static bool needs_quotes_for_logfmt(const char *s)
return false;
}

/*
* FIXME: Attribute added because address sanitizer reports a log-related
* issue when running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
static void string_to_logfmt(BUFFER *wb, const char *s)
{
bool spaces = needs_quotes_for_logfmt(s);
Expand All @@ -1631,11 +1621,6 @@ static void string_to_logfmt(BUFFER *wb, const char *s)
buffer_fast_strcat(wb, "\"", 1);
}

/*
* FIXME: Attribute added because address sanitizer reports a log-related
* issue when running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
static void nd_logger_logfmt(BUFFER *wb, struct log_field *fields, size_t fields_max)
{

Expand Down Expand Up @@ -2170,8 +2155,8 @@ static void nd_logger(const char *file, const char *function, const unsigned lon
if(likely(!thread_log_fields[NDF_TID].entry.set))
thread_log_fields[NDF_TID].entry = ND_LOG_FIELD_U64(NDF_TID, gettid());

char os_threadname[NETDATA_THREAD_NAME_MAX + 1];
if(likely(!thread_log_fields[NDF_THREAD_TAG].entry.set)) {
char os_threadname[NETDATA_THREAD_NAME_MAX + 1];
const char *thread_tag = netdata_thread_tag();
if(!netdata_thread_tag_exists()) {
if (!netdata_thread_tag_exists()) {
Expand Down Expand Up @@ -2260,11 +2245,6 @@ static ND_LOG_SOURCES nd_log_validate_source(ND_LOG_SOURCES source) {
// ----------------------------------------------------------------------------
// public API for loggers

/*
* FIXME: Attribute added because address sanitizer reports a log-related
* issue when running the agent with `-W unittest`.
*/
__attribute__((no_sanitize("address")))
void netdata_logger(ND_LOG_SOURCES source, ND_LOG_FIELD_PRIORITY priority, const char *file, const char *function, unsigned long line, const char *fmt, ... )
{
int saved_errno = errno;
Expand Down

0 comments on commit 989c856

Please sign in to comment.