Skip to content

Commit

Permalink
Protect analytics set data (netdata#16929)
Browse files Browse the repository at this point in the history
  • Loading branch information
stelfrag authored Feb 5, 2024
1 parent 908d8b6 commit 4299ff7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions daemon/analytics.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ void analytics_free_data(void)
*/
void analytics_set_data(char **name, char *value)
{
spinlock_lock(&analytics_data.spinlock);
if (*name) {
analytics_data.data_length -= strlen(*name);
freez(*name);
}
*name = strdupz(value);
analytics_data.data_length += strlen(*name);
spinlock_unlock(&analytics_data.spinlock);
}

/*
Expand All @@ -130,6 +132,7 @@ void analytics_set_data(char **name, char *value)
void analytics_set_data_str(char **name, const char *value)
{
size_t value_string_len;
spinlock_lock(&analytics_data.spinlock);
if (*name) {
analytics_data.data_length -= strlen(*name);
freez(*name);
Expand All @@ -138,6 +141,7 @@ void analytics_set_data_str(char **name, const char *value)
*name = mallocz(sizeof(char) * value_string_len);
snprintfz(*name, value_string_len - 1, "\"%s\"", value);
analytics_data.data_length += strlen(*name);
spinlock_unlock(&analytics_data.spinlock);
}

/*
Expand Down Expand Up @@ -466,6 +470,8 @@ void analytics_alarms(void)
*/
void analytics_misc(void)
{
analytics_data.spinlock.locked = false;

#ifdef ENABLE_ACLK
analytics_set_data(&analytics_data.netdata_host_cloud_available, "true");
analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation");
Expand Down
1 change: 1 addition & 0 deletions daemon/analytics.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct analytics_data {

size_t charts_count;
size_t metrics_count;
SPINLOCK spinlock;

bool exporting_enabled;
};
Expand Down

0 comments on commit 4299ff7

Please sign in to comment.