Skip to content

Commit

Permalink
handle invalid topic length instead of crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Sep 12, 2024
1 parent 7724cee commit 8a37811
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/packet.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ pub const PacketType = enum(u4) {
disconnect,
};

pub const ParseError = error{
InvalidQoS,
UnhandledPacket,
};
pub const ParseError = error{ InvalidQoS, UnhandledPacket, InvalidTopicLength };

pub const Packet = union(PacketType) {
connect: Connect,
Expand Down Expand Up @@ -77,6 +74,9 @@ pub const Packet = union(PacketType) {
const topic_length = try reader.readInt(u16, .big);
const topic_start = try fis.getPos();
const topic_end = topic_start + topic_length;
if (topic_end >= buffer.len) {
return error.InvalidTopicLength;
}
const topic = buffer[topic_start..topic_end];
try fis.seekBy(topic_length);

Expand Down

0 comments on commit 8a37811

Please sign in to comment.