Skip to content

Commit

Permalink
Fixed #379.
Browse files Browse the repository at this point in the history
Fixed MQTT allowed UTF-8 contents checking.
Fixed reason_code. If invalid UTF-8 detected, the reason_code should be malformed_packet.
  • Loading branch information
redboltz committed Dec 10, 2024
1 parent 455c155 commit 84178c5
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 421 deletions.
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/detail/base_property.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct string_property : binary_property {
}
else {
return make_error_code(
disconnect_reason_code::protocol_error
disconnect_reason_code::malformed_packet
);
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ struct len_str {
}
else {
return make_error_code(
disconnect_reason_code::protocol_error
disconnect_reason_code::malformed_packet
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions include/async_mqtt/packet/impl/v3_1_1_connect.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ connect_packet::connect_packet(
if (!utf8string_check(client_id_)) {
throw system_error(
make_error_code(
connect_reason_code::client_identifier_not_valid
connect_reason_code::malformed_packet
)
);
}
Expand All @@ -92,7 +92,7 @@ connect_packet::connect_packet(
if (!utf8string_check(*user_name)) {
throw system_error(
make_error_code(
connect_reason_code::bad_user_name_or_password
connect_reason_code::malformed_packet
)
);
}
Expand All @@ -114,7 +114,7 @@ connect_packet::connect_packet(
if (!utf8string_check(w->topic())) {
throw system_error(
make_error_code(
connect_reason_code::topic_name_invalid
connect_reason_code::malformed_packet
)
);
}
Expand Down Expand Up @@ -365,7 +365,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
client_id_ = buf.substr(0, client_id_length);
if (!utf8string_check(client_id_)) {
ec = make_error_code(
connect_reason_code::client_identifier_not_valid
connect_reason_code::malformed_packet
);
return;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
will_topic_ = buf.substr(0, will_topic_length);
if (!utf8string_check(will_topic_)) {
ec = make_error_code(
connect_reason_code::topic_name_invalid
connect_reason_code::malformed_packet
);
return;
}
Expand Down Expand Up @@ -463,7 +463,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
user_name_ = buf.substr(0, user_name_length);
if (!utf8string_check(user_name_)) {
ec = make_error_code(
connect_reason_code::bad_user_name_or_password
connect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v3_1_1_publish.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ basic_publish_packet<PacketIdBytes>::basic_publish_packet(
if (!utf8string_check(topic_name_)) {
throw system_error(
make_error_code(
disconnect_reason_code::topic_name_invalid
disconnect_reason_code::malformed_packet
)
);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ basic_publish_packet<PacketIdBytes>::basic_publish_packet(buffer buf, error_code

if (!utf8string_check(topic_name_)) {
ec = make_error_code(
disconnect_reason_code::topic_name_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v3_1_1_subscribe.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ basic_subscribe_packet<PacketIdBytes>::basic_subscribe_packet(
if (!utf8string_check(e.all_topic())) {
throw system_error{
make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
)
};
}
Expand Down Expand Up @@ -240,7 +240,7 @@ basic_subscribe_packet<PacketIdBytes>::basic_subscribe_packet(buffer buf, error_

if (!utf8string_check(topic)) {
ec = make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v3_1_1_unsubscribe.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ basic_unsubscribe_packet<PacketIdBytes>::basic_unsubscribe_packet(
if (!utf8string_check(e.all_topic())) {
throw system_error{
make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
)
};
}
Expand Down Expand Up @@ -207,7 +207,7 @@ basic_unsubscribe_packet<PacketIdBytes>::basic_unsubscribe_packet(buffer buf, er
auto topic = buf.substr(0, topic_length);
if (!utf8string_check(topic)) {
ec = make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
12 changes: 6 additions & 6 deletions include/async_mqtt/packet/impl/v5_connect.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ connect_packet::connect_packet(
if (!utf8string_check(client_id_)) {
throw system_error{
make_error_code(
connect_reason_code::client_identifier_not_valid
connect_reason_code::malformed_packet
)
};
}
Expand All @@ -102,7 +102,7 @@ connect_packet::connect_packet(
if (!utf8string_check(*user_name)) {
throw system_error{
make_error_code(
connect_reason_code::bad_user_name_or_password
connect_reason_code::malformed_packet
)
};
}
Expand Down Expand Up @@ -143,7 +143,7 @@ connect_packet::connect_packet(
if (!utf8string_check(w->topic())) {
throw system_error{
make_error_code(
connect_reason_code::topic_name_invalid
connect_reason_code::malformed_packet
)
};
}
Expand Down Expand Up @@ -453,7 +453,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
client_id_ = buf.substr(0, client_id_length);
if (!utf8string_check(client_id_)) {
ec = make_error_code(
connect_reason_code::client_identifier_not_valid
connect_reason_code::malformed_packet
);
return;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
will_topic_ = buf.substr(0, will_topic_length);
if (!utf8string_check(will_topic_)) {
ec = make_error_code(
connect_reason_code::topic_name_invalid
connect_reason_code::malformed_packet
);
return;
}
Expand Down Expand Up @@ -577,7 +577,7 @@ connect_packet::connect_packet(buffer buf, error_code& ec) {
user_name_ = buf.substr(0, user_name_length);
if (!utf8string_check(user_name_)) {
ec = make_error_code(
connect_reason_code::bad_user_name_or_password
connect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v5_publish.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ basic_publish_packet<PacketIdBytes>::basic_publish_packet(
if (!utf8string_check(topic_name_)) {
throw system_error(
make_error_code(
disconnect_reason_code::topic_name_invalid
disconnect_reason_code::malformed_packet
)
);
}
Expand Down Expand Up @@ -436,7 +436,7 @@ basic_publish_packet<PacketIdBytes>::basic_publish_packet(buffer buf, error_code

if (!utf8string_check(topic_name_)) {
ec = make_error_code(
disconnect_reason_code::topic_name_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v5_subscribe.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ basic_subscribe_packet<PacketIdBytes>::basic_subscribe_packet(
if (!utf8string_check(e.all_topic())) {
throw system_error{
make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
)
};
}
Expand Down Expand Up @@ -313,7 +313,7 @@ basic_subscribe_packet<PacketIdBytes>::basic_subscribe_packet(buffer buf, error_

if (!utf8string_check(topic)) {
ec = make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/async_mqtt/packet/impl/v5_unsubscribe.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ basic_unsubscribe_packet<PacketIdBytes>::basic_unsubscribe_packet(
if (!utf8string_check(e.all_topic())) {
throw system_error(
make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
)
);
}
Expand Down Expand Up @@ -270,7 +270,7 @@ basic_unsubscribe_packet<PacketIdBytes>::basic_unsubscribe_packet(buffer buf, er
auto topic = buf.substr(0, topic_length);
if (!utf8string_check(topic)) {
ec = make_error_code(
disconnect_reason_code::topic_filter_invalid
disconnect_reason_code::malformed_packet
);
return;
}
Expand Down
Loading

0 comments on commit 84178c5

Please sign in to comment.