Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ if(USE_GCOV)
endif(USE_GCOV)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=format-truncation")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O0")
add_compile_options(-fstack-protector-strong)
add_link_options(-fstack-protector-strong)

if(NOT DISABLE_ASAN)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -fsanitize=address")
Expand Down
2 changes: 1 addition & 1 deletion include/neuron/define.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#define NEU_CID_LEN4 4
#define NEU_CID_LEN8 8
#define NEU_CID_LEN16 16
#define NEU_CID_LEN32 32
#define NEU_CID_LEN32 72
#define NEU_CID_LEN64 64

#define CHECK_NODE_NAME_LENGTH_ERR \
Expand Down
9 changes: 5 additions & 4 deletions plugins/ekuiper/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ void recv_data_callback(void *arg)
body_str = nng_msg_body(msg);
body_len = nng_msg_len(msg);

if (*(uint8_t *) body_str == 0x0A && *(uint8_t *) (body_str + 1) == 0xCE) {
if (body_len >= 26 && *(uint8_t *) body_str == 0x0A &&
*(uint8_t *) (body_str + 1) == 0xCE) {
// trace
trace_id = (uint8_t *) (body_str + 2);
span_id = (uint8_t *) (body_str + 18);
Expand Down Expand Up @@ -327,7 +328,7 @@ static int send_write_tag_req(neu_plugin_t *plugin, neu_json_write_req_t *req,
header.ctx = calloc(1, 48 + strlen(playload) + 1);
binary_to_hex(trace_id, 16, header.ctx);
binary_to_hex(span_id, 8, header.ctx + 32);
strcpy(header.ctx + 48, playload);
strncpy(header.ctx + 48, playload, strlen(playload));
}

neu_req_write_tag_t cmd = {
Expand Down Expand Up @@ -374,7 +375,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
header.ctx = calloc(1, 48 + strlen(playload) + 1);
binary_to_hex(trace_id, 16, header.ctx);
binary_to_hex(span_id, 8, header.ctx + 32);
strcpy(header.ctx + 48, playload);
strncpy(header.ctx + 48, playload, strlen(playload));
}

neu_req_write_tags_t cmd = { 0 };
Expand All @@ -387,7 +388,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
}

for (int i = 0; i < cmd.n_tag; i++) {
strcpy(cmd.tags[i].tag, req->tags[i].tag);
strncpy(cmd.tags[i].tag, req->tags[i].tag, NEU_TAG_NAME_LEN - 1);
if (0 !=
json_value_to_tag_value(&req->tags[i].value, req->tags[i].t,
&cmd.tags[i].value)) {
Expand Down
40 changes: 29 additions & 11 deletions src/adapter/driver/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ inline static tkey_t to_key(const char *group, const char *tag)
{
tkey_t key = { 0 };

strcpy(key.group, group);
strcpy(key.tag, tag);
strncpy(key.group, group, sizeof(key.group) - 1);
strncpy(key.tag, tag, sizeof(key.tag) - 1);

return key;
}
Expand Down Expand Up @@ -160,8 +160,8 @@ void neu_driver_cache_add(neu_driver_cache_t *cache, const char *group,
if (elem == NULL) {
elem = calloc(1, sizeof(struct elem));

strcpy(elem->key.group, group);
strcpy(elem->key.tag, tag);
snprintf(elem->key.group, sizeof(elem->key.group), "%s", group);
snprintf(elem->key.tag, sizeof(elem->key.tag), "%s", tag);

HASH_ADD(hh, cache->table, key, sizeof(tkey_t), elem);
}
Expand All @@ -179,15 +179,15 @@ void neu_driver_cache_update_trace(neu_driver_cache_t *cache, const char *group,
group_trace_t *elem = NULL;
char key[NEU_GROUP_NAME_LEN] = { 0 };

strcpy(key, group);
snprintf(key, sizeof(key), "%s", group);

pthread_mutex_lock(&cache->mtx);
HASH_FIND(hh, cache->trace_table, &key, sizeof(key), elem);

if (elem == NULL) {
elem = calloc(1, sizeof(group_trace_t));

strcpy(elem->key, group);
snprintf(elem->key, sizeof(elem->key), "%s", group);
elem->trace_ctx = trace_ctx;

HASH_ADD(hh, cache->trace_table, key, sizeof(key), elem);
Expand All @@ -205,7 +205,7 @@ void *neu_driver_cache_get_trace(neu_driver_cache_t *cache, const char *group)

void *trace = NULL;

strcpy(key, group);
snprintf(key, sizeof(key), "%s", group);

pthread_mutex_lock(&cache->mtx);
HASH_FIND(hh, cache->trace_table, &key, sizeof(key), elem);
Expand Down Expand Up @@ -275,7 +275,7 @@ bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
elem->changed = true;
tag_changed = true;
} else {
if (memcpy(elem->value_old.value.bytes.bytes,
if (memcmp(elem->value_old.value.bytes.bytes,
value.value.bytes.bytes,
value.value.bytes.length) != 0) {
elem->changed = true;
Expand Down Expand Up @@ -459,7 +459,7 @@ bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
break;
case NEU_TYPE_CUSTOM: {
if (json_equal(elem->value_old.value.json, value.value.json) !=
0) {
1) {
elem->changed = true;
tag_changed = true;
}
Expand Down Expand Up @@ -542,7 +542,7 @@ bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
elem->changed = true;
tag_changed = true;
} else {
if (memcpy(elem->value.value.bytes.bytes,
if (memcmp(elem->value.value.bytes.bytes,
value.value.bytes.bytes,
value.value.bytes.length) != 0) {
elem->changed = true;
Expand Down Expand Up @@ -720,7 +720,7 @@ bool neu_driver_cache_update_change(neu_driver_cache_t *cache,
break;
}
case NEU_TYPE_CUSTOM: {
if (json_equal(elem->value.value.json, value.value.json) != 0) {
if (json_equal(elem->value.value.json, value.value.json) != 1) {
elem->changed = true;
tag_changed = true;
}
Expand Down Expand Up @@ -1266,3 +1266,21 @@ void neu_driver_cache_del(neu_driver_cache_t *cache, const char *group,

pthread_mutex_unlock(&cache->mtx);
}

void neu_driver_cache_rename(neu_driver_cache_t *cache, const char *group,
const char *old_tag, const char *new_tag)
{
struct elem *elem = NULL;
tkey_t key = to_key(group, old_tag);

pthread_mutex_lock(&cache->mtx);
HASH_FIND(hh, cache->table, &key, sizeof(tkey_t), elem);

if (elem != NULL) {
HASH_DEL(cache->table, elem);
elem->key = to_key(group, new_tag);
HASH_ADD(hh, cache->table, key, sizeof(tkey_t), elem);
}

pthread_mutex_unlock(&cache->mtx);
}
6 changes: 3 additions & 3 deletions src/connection/connection_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ int neu_conn_eth_check_interface(const char *interface)
return -1;
}

strcpy(ifr.ifr_name, interface);
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
ret = ioctl(fd, SIOCGIFHWADDR, &ifr);
if (ret != 0) {
return -1;
Expand Down Expand Up @@ -302,7 +302,7 @@ static int get_mac(neu_conn_eth_t *conn, const char *interface)
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
int ret = -1;

strcpy(ifr.ifr_name, interface);
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
memcpy(conn->ic->mac, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
ret = 0;
Expand All @@ -328,7 +328,7 @@ static int init_socket(const char *interface, uint16_t protocol, uint8_t mac[6])
(void) mac;
(void) pn_mcast_addr;

strcpy(ifr.ifr_name, interface);
snprintf(ifr.ifr_name, IFNAMSIZ, "%s", interface);
if (ioctl(fd, SIOCGIFINDEX, &ifr) != 0) {
close(fd);
return -1;
Expand Down
3 changes: 2 additions & 1 deletion src/core/plugin_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ int neu_plugin_manager_find(neu_plugin_manager_t *mgr, const char *plugin_name,
info->kind = plugin->kind;

if (plugin->single_name != NULL) {
strcpy(info->single_name, plugin->single_name);
snprintf(info->single_name, sizeof(info->single_name), "%s",
plugin->single_name);
}
strncpy(info->name, plugin->name, sizeof(info->name));
strncpy(info->library, plugin->lib_name, sizeof(info->library));
Expand Down
47 changes: 30 additions & 17 deletions src/otel/otel_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#define SPAN_ID_LENGTH 16
#define ID_CHARSET "0123456789abcdef"
#define TRACE_TIME_OUT (3 * 60 * 1000)
#define TRACE_TIME_OUT (60 * 1000)

bool otel_flag = false;
char otel_collector_url[128] = { 0 };
Expand Down Expand Up @@ -1033,29 +1033,32 @@ void neu_otel_split_traceparent(const char *in, char *trace_id, char *span_id,
char * copy = strdup(in);
char t_flags[32] = { 0 };

const size_t trace_id_cap = 64;
const size_t span_id_cap = 32;

token = strtok_r(copy, delimiter, &saveptr);

token = strtok_r(NULL, delimiter, &saveptr);
if (token != NULL) {
strcpy(trace_id, token);
snprintf(trace_id, trace_id_cap, "%s", token);
} else {
strcpy(trace_id, "");
trace_id[0] = '\0';
}

token = strtok_r(NULL, delimiter, &saveptr);
if (token != NULL) {
strcpy(span_id, token);
snprintf(span_id, span_id_cap, "%s", token);
} else {
strcpy(span_id, "");
span_id[0] = '\0';
}

token = strtok_r(NULL, delimiter, &saveptr);
if (token != NULL) {
strcpy(t_flags, token);
snprintf(t_flags, sizeof(t_flags), "%s", token);
sscanf(t_flags, "%x", flags);
} else {
strcpy(t_flags, "");
*flags = 0;
t_flags[0] = '\0';
*flags = 0;
}

free(copy);
Expand All @@ -1072,25 +1075,33 @@ static int otel_timer_cb(void *data)

HASH_ITER(hh, traces_table, el, tmp)
{
bool should_send = false;
bool is_timeout = false;

if (neu_time_ms() - el->ctx->ts >= TRACE_TIME_OUT) {
nlog_debug("trace:%s time out", (char *) el->ctx->trace_id);
HASH_DEL(traces_table, el);
neu_otel_free_trace(el->ctx);
free(el);
should_send = true;
is_timeout = true;
nlog_debug("trace:%s time out, reporting incomplete trace",
(char *) el->ctx->trace_id);
} else if (el->ctx->final &&
el->ctx->span_num ==
el->ctx->trace_data.resource_spans[0]
->scope_spans[0]
->n_spans &&
el->ctx->expected_span_num <= 0) {
int data_size = neu_otel_trace_pack_size(el->ctx);
should_send = true;
}

uint8_t *data_buf = calloc(1, data_size);
if (should_send) {
int data_size = neu_otel_trace_pack_size(el->ctx);
uint8_t *data_buf = calloc(1, data_size);
neu_otel_trace_pack(el->ctx, data_buf);
int status = neu_http_post_otel_trace(data_buf, data_size);
free(data_buf);
nlog_debug("send trace:%s status:%d", (char *) el->ctx->trace_id,
nlog_debug("send %strace:%s status:%d",
is_timeout ? "timeout " : "", (char *) el->ctx->trace_id,
status);

if (status == 200 || status == 400) {
HASH_DEL(traces_table, el);
neu_otel_free_trace(el->ctx);
Expand Down Expand Up @@ -1175,10 +1186,12 @@ void neu_otel_set_config(void *config)
otel_control_flag = req->control_flag;
otel_data_flag = req->data_flag;
if (req->collector_url) {
strcpy(otel_collector_url, req->collector_url);
snprintf(otel_collector_url, sizeof(otel_collector_url), "%s",
req->collector_url);
}
if (req->service_name) {
strcpy(otel_service_name, req->service_name);
snprintf(otel_service_name, sizeof(otel_service_name), "%s",
req->service_name);
}
otel_data_sample_rate = req->data_sample_rate;

Expand Down
Loading
Loading