Skip to content

Commit f80ffdc

Browse files
author
fengzero
committed
ci: codeQL
1 parent 2fa7186 commit f80ffdc

37 files changed

Lines changed: 777 additions & 514 deletions

‎.github/workflows/check.yml‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
# checkout
16-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v6
1717
with:
1818
submodules: recursive
1919

@@ -40,6 +40,18 @@ jobs:
4040
cppcheck --enable=all --error-exitcode=2 --inline-suppr --suppress=missingInclude --suppress=unusedFunction --suppress=*:src/otel/trace.pb-c.c --suppress=*:src/otel/common.pb-c.c --suppress=*:src/otel/resource.pb-c.c ./plugins ./src
4141
cppcheck --enable=all --error-exitcode=2 --inline-suppr --suppress=missingInclude --suppress=variableScope ./simulator
4242
43+
flawfinder:
44+
name: Flawfinder Scan
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v6
49+
50+
- name: flawfinder_scan
51+
uses: david-a-wheeler/flawfinder@2.0.20
52+
with:
53+
arguments: '--minlevel=3 .'
54+
4355
build:
4456
runs-on: ubuntu-24.04
4557
container: ghcr.io/neugates/build:x86_64-main

‎include/neuron/define.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@
9898
#define NEU_CID_LEN32 32
9999
#define NEU_CID_LEN64 64
100100

101+
#define NEU_TRACE_ID_LEN 64
102+
#define NEU_SPAN_ID_LEN 32
103+
101104
#define CHECK_NODE_NAME_LENGTH_ERR \
102105
do { \
103106
NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_NAME_TOO_LONG, { \

‎include/neuron/msg.h‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ static inline void neu_req_add_tag_fini(neu_req_add_tag_t *req)
671671
static inline int neu_req_add_tag_copy(neu_req_add_tag_t *dst,
672672
neu_req_add_tag_t *src)
673673
{
674-
strcpy(dst->driver, src->driver);
675-
strcpy(dst->group, src->group);
674+
strncpy(dst->driver, src->driver, NEU_NODE_NAME_LEN);
675+
strncpy(dst->group, src->group, NEU_GROUP_NAME_LEN);
676676
dst->tags = (neu_datatag_t *) calloc(src->n_tag, sizeof(src->tags[0]));
677677
if (NULL == dst->tags) {
678678
return -1;
@@ -707,8 +707,8 @@ static inline void neu_req_del_tag_fini(neu_req_del_tag_t *req)
707707
static inline int neu_req_del_tag_copy(neu_req_del_tag_t *dst,
708708
neu_req_del_tag_t *src)
709709
{
710-
strcpy(dst->driver, src->driver);
711-
strcpy(dst->group, src->group);
710+
strncpy(dst->driver, src->driver, NEU_NODE_NAME_LEN);
711+
strncpy(dst->group, src->group, NEU_GROUP_NAME_LEN);
712712
dst->tags = (char **) calloc(src->n_tag, sizeof(src->tags[0]));
713713
if (NULL == dst->tags) {
714714
return -1;
@@ -863,7 +863,7 @@ static inline void neu_req_node_setting_fini(neu_req_node_setting_t *req)
863863
static inline int neu_req_node_setting_copy(neu_req_node_setting_t *dst,
864864
neu_req_node_setting_t *src)
865865
{
866-
strcpy(dst->node, src->node);
866+
strncpy(dst->node, src->node, NEU_NODE_NAME_LEN);
867867
dst->setting = strdup(src->setting);
868868
return dst->setting ? 0 : -1;
869869
}
@@ -1696,13 +1696,13 @@ inline static void neu_msg_exchange(neu_reqresp_head_t *header)
16961696
{
16971697
char tmp[NEU_NODE_NAME_LEN] = { 0 };
16981698

1699-
strcpy(tmp, header->sender);
1699+
strncpy(tmp, header->sender, sizeof(tmp) - 1);
17001700

17011701
memset(header->sender, 0, sizeof(header->sender));
1702-
strcpy(header->sender, header->receiver);
1702+
strncpy(header->sender, header->receiver, sizeof(header->sender) - 1);
17031703

17041704
memset(header->receiver, 0, sizeof(header->receiver));
1705-
strcpy(header->receiver, tmp);
1705+
strncpy(header->receiver, tmp, sizeof(header->receiver) - 1);
17061706
}
17071707

17081708
typedef struct {

‎include/neuron/utils/uthash.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ do {
513513
*/
514514
#ifdef HASH_DEBUG
515515
#include <stdio.h> /* fprintf, stderr */
516-
#define HASH_OOPS(...) do { fprintf(stderr, __VA_ARGS__); exit(-1); } while (0)
516+
#define HASH_OOPS(...) do { fprintf(stderr, "%s", __VA_ARGS__); exit(-1); } while (0)
517517
#define HASH_FSCK(hh,head,where) \
518518
do { \
519519
struct UT_hash_handle *_thh; \

‎plugins/ekuiper/read_write.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int send_write_tag_req(neu_plugin_t *plugin, neu_json_write_req_t *req,
327327
header.ctx = calloc(1, 48 + strlen(playload) + 1);
328328
binary_to_hex(trace_id, 16, header.ctx);
329329
binary_to_hex(span_id, 8, header.ctx + 32);
330-
strcpy(header.ctx + 48, playload);
330+
strncpy(header.ctx + 48, playload, strlen(playload));
331331
}
332332

333333
neu_req_write_tag_t cmd = {
@@ -374,7 +374,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
374374
header.ctx = calloc(1, 48 + strlen(playload) + 1);
375375
binary_to_hex(trace_id, 16, header.ctx);
376376
binary_to_hex(span_id, 8, header.ctx + 32);
377-
strcpy(header.ctx + 48, playload);
377+
strncpy(header.ctx + 48, playload, strlen(playload));
378378
}
379379

380380
neu_req_write_tags_t cmd = { 0 };
@@ -387,7 +387,7 @@ static int send_write_tags_req(neu_plugin_t * plugin,
387387
}
388388

389389
for (int i = 0; i < cmd.n_tag; i++) {
390-
strcpy(cmd.tags[i].tag, req->tags[i].tag);
390+
strncpy(cmd.tags[i].tag, req->tags[i].tag, NEU_TAG_NAME_LEN);
391391
if (0 !=
392392
json_value_to_tag_value(&req->tags[i].value, req->tags[i].t,
393393
&cmd.tags[i].value)) {

‎plugins/mqtt/mqtt_handle.c‎

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void to_traceparent(uint8_t *trace_id, char *span_id, char *out)
3939
size += sprintf(out + size, "%02x", trace_id[i]);
4040
}
4141

42-
sprintf(out + size, "-%s-01", span_id);
42+
snprintf(out + size, strlen(span_id) + 5, "-%s-01", span_id);
4343
}
4444

4545
static int tag_values_to_json(UT_array *tags, mqtt_static_vt_t *s_tags,
@@ -465,7 +465,7 @@ static int send_write_tags_req(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
465465
}
466466

467467
for (int i = 0; i < cmd.n_tag; i++) {
468-
strcpy(cmd.tags[i].tag, req->tags[i].tag);
468+
strncpy(cmd.tags[i].tag, req->tags[i].tag, NEU_TAG_NAME_LEN);
469469
if (0 !=
470470
json_value_to_tag_value(&req->tags[i].value, req->tags[i].t,
471471
&cmd.tags[i].value)) {
@@ -618,7 +618,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
618618
}
619619

620620
for (int i = 0; i < cmd.n_tag; i++) {
621-
strcpy(cmd.tags[i].tag, wr->tags[i]->name);
621+
strncpy(cmd.tags[i].tag, wr->tags[i]->name, NEU_TAG_NAME_LEN);
622622
switch (wr->tags[i]->value->value_case) {
623623
case MODEL__DATA_ITEM_VALUE__VALUE_INT_VALUE:
624624
cmd.tags[i].value.type = NEU_TYPE_INT64;
@@ -635,8 +635,8 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
635635
break;
636636
case MODEL__DATA_ITEM_VALUE__VALUE_STRING_VALUE:
637637
cmd.tags[i].value.type = NEU_TYPE_STRING;
638-
strcpy(cmd.tags[i].value.value.str,
639-
wr->tags[i]->value->string_value);
638+
strncpy(cmd.tags[i].value.value.str,
639+
wr->tags[i]->value->string_value, NEU_VALUE_SIZE);
640640
break;
641641
default:
642642
break;
@@ -932,7 +932,7 @@ void handle_driver_action_req(neu_mqtt_qos_e qos, const char *topic,
932932
mqtt->tracestate = NULL;
933933

934934
header.ctx = mqtt;
935-
strcpy(cmd.driver, dar->node);
935+
strncpy(cmd.driver, dar->node, NEU_NODE_NAME_LEN);
936936
cmd.action = strdup(dar->action);
937937

938938
model__driver_action_request__free_unpacked(dar, NULL);
@@ -955,7 +955,7 @@ void handle_driver_action_req(neu_mqtt_qos_e qos, const char *topic,
955955
}
956956

957957
header.ctx = mqtt;
958-
strcpy(cmd.driver, req->driver);
958+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
959959
cmd.action = strdup(req->action);
960960
neu_json_decode_driver_action_req_free(req);
961961
free(json_str);
@@ -1793,8 +1793,8 @@ void handle_driver_directory_req(neu_mqtt_qos_e qos, const char *topic,
17931793
mqtt->tracestate = NULL;
17941794

17951795
header.ctx = mqtt;
1796-
strcpy(cmd.driver, flr->node);
1797-
strcpy(cmd.path, flr->path);
1796+
strncpy(cmd.driver, flr->node, NEU_NODE_NAME_LEN);
1797+
strncpy(cmd.path, flr->path, NEU_PATH_LEN);
17981798

17991799
model__file_list_request__free_unpacked(flr, NULL);
18001800
} else {
@@ -1817,8 +1817,8 @@ void handle_driver_directory_req(neu_mqtt_qos_e qos, const char *topic,
18171817

18181818
header.ctx = mqtt;
18191819

1820-
strcpy(cmd.driver, req->driver);
1821-
strcpy(cmd.path, req->path);
1820+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
1821+
strncpy(cmd.path, req->path, NEU_PATH_LEN);
18221822

18231823
neu_json_decode_driver_directory_req_free(req);
18241824
free(json_str);
@@ -1982,8 +1982,8 @@ void handle_driver_fup_open_req(neu_mqtt_qos_e qos, const char *topic,
19821982
mqtt->tracestate = NULL;
19831983

19841984
header.ctx = mqtt;
1985-
strcpy(cmd.driver, fur->node);
1986-
strcpy(cmd.path, fur->path);
1985+
strncpy(cmd.driver, fur->node, NEU_NODE_NAME_LEN);
1986+
strncpy(cmd.path, fur->path, NEU_PATH_LEN);
19871987

19881988
model__file_upload_request__free_unpacked(fur, NULL);
19891989
} else {
@@ -2004,8 +2004,8 @@ void handle_driver_fup_open_req(neu_mqtt_qos_e qos, const char *topic,
20042004
return;
20052005
}
20062006
header.ctx = mqtt;
2007-
strcpy(cmd.driver, req->driver);
2008-
strcpy(cmd.path, req->path);
2007+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
2008+
strncpy(cmd.path, req->path, NEU_PATH_LEN);
20092009

20102010
neu_json_decode_driver_fup_open_req_free(req);
20112011
free(json_str);
@@ -2109,8 +2109,8 @@ void handle_driver_fup_data_req(neu_mqtt_qos_e qos, const char *topic,
21092109

21102110
header.ctx = mqtt;
21112111

2112-
strcpy(cmd.driver, fudr->node);
2113-
strcpy(cmd.path, fudr->path);
2112+
strncpy(cmd.driver, fudr->node, NEU_NODE_NAME_LEN);
2113+
strncpy(cmd.path, fudr->path, NEU_PATH_LEN);
21142114

21152115
model__file_upload_data_request__free_unpacked(fudr, NULL);
21162116
} else {
@@ -2133,8 +2133,8 @@ void handle_driver_fup_data_req(neu_mqtt_qos_e qos, const char *topic,
21332133

21342134
header.ctx = mqtt;
21352135

2136-
strcpy(cmd.driver, req->driver);
2137-
strcpy(cmd.path, req->path);
2136+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
2137+
strncpy(cmd.path, req->path, NEU_PATH_LEN);
21382138

21392139
neu_json_decode_driver_fup_data_req_free(req);
21402140
free(json_str);
@@ -2243,9 +2243,9 @@ void handle_driver_fdown_open_req(neu_mqtt_qos_e qos, const char *topic,
22432243
mqtt->tracestate = NULL;
22442244

22452245
header.ctx = mqtt;
2246-
strcpy(cmd.driver, fdr->node);
2247-
strcpy(cmd.src_path, fdr->src_path);
2248-
strcpy(cmd.dst_path, fdr->dst_path);
2246+
strncpy(cmd.driver, fdr->node, NEU_NODE_NAME_LEN);
2247+
strncpy(cmd.src_path, fdr->src_path, NEU_PATH_LEN);
2248+
strncpy(cmd.dst_path, fdr->dst_path, NEU_PATH_LEN);
22492249
cmd.size = fdr->size;
22502250

22512251
model__file_download_request__free_unpacked(fdr, NULL);
@@ -2267,9 +2267,9 @@ void handle_driver_fdown_open_req(neu_mqtt_qos_e qos, const char *topic,
22672267
return;
22682268
}
22692269
header.ctx = mqtt;
2270-
strcpy(cmd.driver, req->driver);
2271-
strcpy(cmd.src_path, req->src_path);
2272-
strcpy(cmd.dst_path, req->dst_path);
2270+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
2271+
strncpy(cmd.src_path, req->src_path, NEU_PATH_LEN);
2272+
strncpy(cmd.dst_path, req->dst_path, NEU_PATH_LEN);
22732273
cmd.size = req->size;
22742274

22752275
neu_json_decode_driver_fdown_open_req_free(req);
@@ -2371,8 +2371,8 @@ void handle_driver_fdown_data_req(neu_mqtt_qos_e qos, const char *topic,
23712371
mqtt->tracestate = NULL;
23722372

23732373
header.ctx = mqtt;
2374-
strcpy(cmd.driver, fddr->node);
2375-
strcpy(cmd.src_path, fddr->path);
2374+
strncpy(cmd.driver, fddr->node, NEU_NODE_NAME_LEN);
2375+
strncpy(cmd.src_path, fddr->path, NEU_PATH_LEN);
23762376
cmd.more = fddr->more;
23772377
cmd.len = fddr->data.len;
23782378
cmd.data = calloc(fddr->data.len, sizeof(uint8_t));
@@ -2398,8 +2398,8 @@ void handle_driver_fdown_data_req(neu_mqtt_qos_e qos, const char *topic,
23982398
}
23992399
header.ctx = mqtt;
24002400

2401-
strcpy(cmd.driver, req->driver);
2402-
strcpy(cmd.src_path, req->src_path);
2401+
strncpy(cmd.driver, req->driver, NEU_NODE_NAME_LEN);
2402+
strncpy(cmd.src_path, req->src_path, NEU_PATH_LEN);
24032403
cmd.more = req->more;
24042404
cmd.len = req->len;
24052405
cmd.data = calloc(req->len, sizeof(uint8_t));

‎plugins/mqtt/schema.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
2424
mqtt_schema_vt_t *vt = &(*vts)[*vts_len - 1];
2525

2626
memset(vt, 0, sizeof(mqtt_schema_vt_t));
27-
strcpy(vt->name, key);
27+
strncpy(vt->name, key, sizeof(vt->name) - 1);
2828

2929
if (strcmp(str_val, "${timestamp}") == 0) {
3030
vt->vt = MQTT_SCHEMA_TIMESTAMP;
@@ -50,7 +50,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
5050
return -1;
5151
} else {
5252
vt->vt = MQTT_SCHEMA_UD;
53-
strcpy(vt->ud, str_val);
53+
strncpy(vt->ud, str_val, sizeof(vt->ud) - 1);
5454
}
5555
}
5656
} else if (json_is_object(value)) {
@@ -63,7 +63,7 @@ static int mqtt_schema_parse(json_t *root, mqtt_schema_vt_t **vts,
6363
mqtt_schema_vt_t *vt = &(*vts)[*vts_len - 1];
6464

6565
memset(vt, 0, sizeof(mqtt_schema_vt_t));
66-
strcpy(vt->name, key);
66+
strncpy(vt->name, key, sizeof(vt->name) - 1);
6767

6868
vt->vt = MQTT_SCHEMA_OBJECT;
6969
return mqtt_schema_parse(value, &vt->sub_vts, &vt->n_sub_vts,
@@ -338,7 +338,7 @@ int mqtt_static_validate(const char *static_tags, mqtt_static_vt_t **vts,
338338
mqtt_static_vt_t *vt = &(*vts)[*vts_len - 1];
339339

340340
memset(vt, 0, sizeof(mqtt_static_vt_t));
341-
strcpy(vt->name, key);
341+
strncpy(vt->name, key, sizeof(vt->name) - 1);
342342

343343
if (json_is_string(value)) {
344344
vt->jtype = NEU_JSON_STR;

0 commit comments

Comments
 (0)