Skip to content

[Bug]: Buffer too small publishing enqueued MQTT messages #4725

Description

@jrouvier

Category

Other

Hardware

Station G2

Firmware Version

2.5.1.88935296

Description

When initially connecting to MQTT a queued message for MQTT that is rather long will cause a panic and reboot. In src/mqtt/MQTT.cpp:471 the buffer is defined as:

        static uint8_t bytes[meshtastic_MeshPacket_size + 64];
        size_t numBytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_ServiceEnvelope_msg, env);

meshtastic_MeshPacket_size is 367, which gives a sum of 431. This probably should be changed to:

        static uint8_t bytes[meshtastic_MqttClientProxyMessage_size];
        size_t numBytes = pb_encode_to_bytes(bytes, sizeof(bytes), &meshtastic_ServiceEnvelope_msg, env);

(meshtastic_MqttClientProxyMessage_size is 501)

Note that other bugs complaining about "reboot loops after enabling wifi" or similar may also be due to this bug.

Relevant log output

DEBUG | ??:??:?? 49 [Router] MQTT onSend - Publishing encrypted message
INFO  | ??:??:?? 49 [Router] MQTT not connected, queueing packet
INFO  | ??:??:?? 53 [mqtt] Using non-TLS-encrypted session
INFO  | ??:??:?? 53 [mqtt] Attempting to connect directly to MQTT server mqtt.bayme.sh, port: 1883, username: meshdev, password: ....
INFO  | ??:??:?? 53 [mqtt] MQTT connected
INFO  | ??:??:?? 53 [mqtt] Subscribing to msh/US/bayarea/2/e/......../+
INFO  | ??:??:?? 53 [mqtt] Subscribing to msh/US/bayarea/2/e/PKI/+
DEBUG | ??:??:?? 53 [mqtt] Publishing enqueued MQTT message
ERROR | ??:??:?? 53 [mqtt] Panic: can't encode protobuf reason='bytes size exceeded'
��@INFO  | ??:??:?? 1 

//\ E S H T /\ S T / C

INFO  | ??:??:?? 1 Booted, wake cause 0 (boot count 1), reset_reason=reset

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions