-
Notifications
You must be signed in to change notification settings - Fork 34
new feature: nng pub/sub bridging #1506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ae826cc
9cc630a
628c200
854b9b4
92ff03d
1933f32
62c5d5b
fca8eff
877632b
bd5a075
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -150,13 +150,6 @@ tcptran_pipe_close(void *arg) | |||||||||||||||||||
| nni_free(p->npipe->subinfol, sizeof(nni_list)); | ||||||||||||||||||||
| p->npipe->subinfol = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||||||||||||||||||||
| if (!p->conf->sqlite.enable && nano_qos_db != NULL) { | ||||||||||||||||||||
| nni_qos_db_remove_all_msg( | ||||||||||||||||||||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||||||||||||||||||||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||||||||||||||||||||
| p->npipe->nano_qos_db = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| nni_lmq_flush(&p->rslmq); | ||||||||||||||||||||
| nni_mtx_unlock(&p->mtx); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -228,6 +221,14 @@ tcptran_pipe_fini(void *arg) | |||||||||||||||||||
| nni_mtx_unlock(&ep->mtx); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| nni_mtx_lock(&p->mtx); | ||||||||||||||||||||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||||||||||||||||||||
| if (p->npipe != NULL && p->conf != NULL && | ||||||||||||||||||||
| !p->conf->sqlite.enable && nano_qos_db != NULL) { | ||||||||||||||||||||
|
Comment on lines
+224
to
+226
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Line 224 dereferences Suggested fix- void *nano_qos_db = p->npipe->nano_qos_db;
- if (p->npipe != NULL && p->conf != NULL &&
+ void *nano_qos_db = NULL;
+ if (p->npipe != NULL) {
+ nano_qos_db = p->npipe->nano_qos_db;
+ }
+ if (p->npipe != NULL && p->conf != NULL &&
!p->conf->sqlite.enable && nano_qos_db != NULL) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| nni_qos_db_remove_all_msg( | ||||||||||||||||||||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||||||||||||||||||||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||||||||||||||||||||
| p->npipe->nano_qos_db = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (p->tcp_cparam) { | ||||||||||||||||||||
| conn_param_free(p->tcp_cparam); //reap thread working | ||||||||||||||||||||
| p->tcp_cparam = NULL; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -153,13 +153,6 @@ tlstran_pipe_close(void *arg) | |||||||||||||||||||
| nni_free(p->npipe->subinfol, sizeof(nni_list)); | ||||||||||||||||||||
| p->npipe->subinfol = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||||||||||||||||||||
| if (!p->conf->sqlite.enable && nano_qos_db != NULL) { | ||||||||||||||||||||
| nni_qos_db_remove_all_msg( | ||||||||||||||||||||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||||||||||||||||||||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||||||||||||||||||||
| p->npipe->nano_qos_db = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| nni_lmq_flush(&p->rslmq); | ||||||||||||||||||||
| nni_mtx_unlock(&p->mtx); | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -235,6 +228,14 @@ tlstran_pipe_fini(void *arg) | |||||||||||||||||||
| nni_mtx_unlock(&ep->mtx); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| nni_mtx_lock(&p->mtx); | ||||||||||||||||||||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||||||||||||||||||||
| if (p->npipe != NULL && p->conf != NULL && | ||||||||||||||||||||
| !p->conf->sqlite.enable && nano_qos_db != NULL) { | ||||||||||||||||||||
|
Comment on lines
+231
to
+233
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix null-deref risk in QoS DB teardown. Line 231 reads Suggested fix- void *nano_qos_db = p->npipe->nano_qos_db;
- if (p->npipe != NULL && p->conf != NULL &&
+ void *nano_qos_db = NULL;
+ if (p->npipe != NULL) {
+ nano_qos_db = p->npipe->nano_qos_db;
+ }
+ if (p->npipe != NULL && p->conf != NULL &&
!p->conf->sqlite.enable && nano_qos_db != NULL) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| nni_qos_db_remove_all_msg( | ||||||||||||||||||||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||||||||||||||||||||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||||||||||||||||||||
| p->npipe->nano_qos_db = NULL; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (p->tcp_cparam) { | ||||||||||||||||||||
| conn_param_free(p->tcp_cparam); | ||||||||||||||||||||
| p->tcp_cparam = NULL; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -616,7 +616,8 @@ wstran_pipe_recv_cb(void *arg) | |
| nni_aio_finish_error(p->ep_aio, rv); | ||
| } else if (uaio != NULL) { | ||
| nni_aio_set_msg(uaio, NULL); | ||
| nni_aio_finish_error(uaio, p->err_code == MQTT_SUCCESS ? rv : p->err_code); | ||
| nni_aio_finish_error(uaio, | ||
| p->err_code == MQTT_SUCCESS ? rv : (int) p->err_code); | ||
| } else { | ||
| // Let protocol layer do the close first. | ||
| nng_stream_close(p->ws); | ||
|
|
@@ -1333,6 +1334,15 @@ wstran_pipe_fini(void *arg) | |
| nni_msg_free(p->tmp_msg); | ||
| nni_lmq_flush(&p->recvlmq); | ||
| nng_free(p->qos_buf, 16 + NNI_NANO_MAX_PACKET_SIZE); | ||
| // must free nano_qos_db in fini for safety | ||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||
| if (p->npipe != NULL && p->conf != NULL && | ||
| !p->conf->sqlite.enable && nano_qos_db != NULL) { | ||
|
Comment on lines
+1338
to
+1340
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard Line 1338 dereferences Suggested fix- void *nano_qos_db = p->npipe->nano_qos_db;
- if (p->npipe != NULL && p->conf != NULL &&
+ void *nano_qos_db = NULL;
+ if (p->npipe != NULL) {
+ nano_qos_db = p->npipe->nano_qos_db;
+ }
+ if (p->npipe != NULL && p->conf != NULL &&
!p->conf->sqlite.enable && nano_qos_db != NULL) {🤖 Prompt for AI Agents |
||
| nni_qos_db_remove_all_msg( | ||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||
| p->npipe->nano_qos_db = NULL; | ||
| } | ||
| nni_mtx_unlock(&p->mtx); | ||
|
|
||
| nng_stream_free(p->ws); | ||
|
|
@@ -1375,13 +1385,7 @@ wstran_pipe_close(void *arg) | |
| nni_free(p->npipe->subinfol, sizeof(nni_list)); | ||
| p->npipe->subinfol = NULL; | ||
| } | ||
| void *nano_qos_db = p->npipe->nano_qos_db; | ||
| if (!p->conf->sqlite.enable && nano_qos_db != NULL) { | ||
| nni_qos_db_remove_all_msg( | ||
| false, nano_qos_db, tran_close_unack_msg_cb); | ||
| nni_qos_db_fini_id_hash(nano_qos_db); | ||
| p->npipe->nano_qos_db = NULL; | ||
| } | ||
|
|
||
| nni_lmq_flush(&p->rslmq); | ||
| nni_mtx_unlock(&p->mtx); | ||
| nng_stream_close(p->ws); | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate adapter inputs before dereference/fallback publish.
originis dereferenced before any null check, and fallback publish can usetopicwithout validating it. Both can trigger crashes on bad inputs.Suggested fix
nng_msg * nng_sub0_msg_adapter(nng_msg *origin, char *topic) { nng_msg *mqtt_msg = NULL; + if (origin == NULL) { + log_error("origin message is NULL"); + return NULL; + } const uint8_t *body = nng_msg_body(origin); size_t body_len = nng_msg_len(origin); @@ if (sep == NULL || sep == ptr) { + if (topic == NULL || topic[0] == '\0') { + log_error("Default topic is required when separator is missing"); + return NULL; + } log_warn("No valid topic/payload separator found in NNG sub0 msg."); mqtt_msg = nano_encode_publish_msg(MQTT_PROTOCOL_VERSION_v311, 0, false, false, body, body_len, NULL, topic, NULL); return mqtt_msg; }🤖 Prompt for AI Agents