Skip to content
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

* FIX [handler] fix #https://github.com/emqx/nanomq/issues/1215 #1243

Merged
merged 1 commit into from
May 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions nanomq/pub_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,10 @@
// variable header
// topic length
pub_packet->var_header.publish.topic_name.body =
(char *) copy_utf8_str(msg_body, &pos, (int *)&len);
if (len >= 0)
(char *) copyn_utf8_str(msg_body, &pos, (int *) &len,
nng_msg_remaining_len(msg) - 3);
if (len >= 0 &&

Check warning

Code scanning / CodeQL

Unsigned comparison to zero Warning

Pointless comparison of unsigned value to zero.
pub_packet->var_header.publish.topic_name.body != NULL)
pub_packet->var_header.publish.topic_name.len = len;
else
return PROTOCOL_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion nanomq/sub_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ decode_sub_msg(nano_work *work)

// TODO Decoding topic has potential buffer overflow
tn->topic.body =
(char *)copy_utf8_str(payload_ptr, (uint32_t *)&bpos, &len_of_topic);
(char *)copyn_utf8_str(payload_ptr, (uint32_t *)&bpos, &len_of_topic, remaining_len);
tn->topic.len = len_of_topic;
log_info("topic: [%s] len: [%d]", tn->topic.body, len_of_topic);
len_of_topic = 0;
Expand Down