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 [mqtt_parser] fix a security issue casued by https://github.com… #952

Merged
merged 1 commit into from
May 18, 2024
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
5 changes: 4 additions & 1 deletion src/sp/protocol/mqtt/mqtt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ int32_t
get_utf8_str(char **dest, const uint8_t *src, uint32_t *pos, size_t max)
{
int32_t str_len = 0;
NNI_GET16(src + (*pos), str_len);
if (max > 0)
if (max - *pos < 2)
return -1;
NNI_GET16(src + (*pos), str_len); // still vulnerable to attack
if (max > 0 && str_len > max)
return -1;

Expand Down
2 changes: 1 addition & 1 deletion src/sp/protocol/mqtt/mqtt_parser_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_get_utf8_str()
uint32_t pos = 0;
char *dest;
// test for correct src.
NUTS_ASSERT(get_utf8_str(&dest, src, &pos, -1) == 5);
NUTS_ASSERT(get_utf8_str(&dest, src, &pos, 8) == 5);
NUTS_MATCH((char *) dest, "$MQTT");
src[2] = 0x04;
pos = 0;
Expand Down
Loading