Browse Source

Enforce JP airtime limits via getMaxTextLen()/getMaxGroupTextLen()

Add getMaxTextLen() and getMaxGroupTextLen() virtual to mesh::Radio
(default 160 bytes). BaseChatMesh uses these instead of the hardcoded
MAX_TEXT_LEN macro for limit checks in composeMsgPacket(),
sendCommandData(), and sendGroupMessage(). Stack buffers remain sized
to MAX_TEXT_LEN as a safe upper bound.
pull/2218/head
me 1 month ago
parent
commit
62067d19de
  1. 3
      src/Dispatcher.h
  2. 11
      src/helpers/BaseChatMesh.cpp
  3. 4
      src/helpers/radiolib/RadioLibWrappers.h

3
src/Dispatcher.h

@ -80,6 +80,9 @@ public:
virtual float getLastSNR() const { return 0; }
virtual bool isAS923_1_JP() const { return false; }
virtual int getMaxTextLen() const { return 10 * 16; } // default 160 bytes
virtual int getMaxGroupTextLen() const { return 10 * 16; } // default 160 bytes
};
/**

11
src/helpers/BaseChatMesh.cpp

@ -419,8 +419,9 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes
mesh::Packet* BaseChatMesh::composeMsgPacket(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char *text, uint32_t& expected_ack) {
int text_len = strlen(text);
if (text_len > MAX_TEXT_LEN) return NULL;
if (attempt > 3 && text_len > MAX_TEXT_LEN-2) return NULL;
int max_len = _radio->getMaxTextLen();
if (text_len > max_len) return NULL;
if (attempt > 3 && text_len > max_len - 2) return NULL;
uint8_t temp[5+MAX_TEXT_LEN+1];
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
@ -460,7 +461,8 @@ int BaseChatMesh::sendMessage(const ContactInfo& recipient, uint32_t timestamp,
int BaseChatMesh::sendCommandData(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& est_timeout) {
int text_len = strlen(text);
if (text_len > MAX_TEXT_LEN) return MSG_SEND_FAILED;
int max_len = _radio->getMaxTextLen();
if (text_len > max_len) return MSG_SEND_FAILED;
uint8_t temp[5+MAX_TEXT_LEN+1];
memcpy(temp, &timestamp, 4); // mostly an extra blob to help make packet_hash unique
@ -493,7 +495,8 @@ bool BaseChatMesh::sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& chan
char *ep = strchr((char *) &temp[5], 0);
int prefix_len = ep - (char *) &temp[5];
if (text_len + prefix_len > MAX_TEXT_LEN) text_len = MAX_TEXT_LEN - prefix_len;
int max_len = _radio->getMaxGroupTextLen();
if (text_len + prefix_len > max_len) text_len = max_len - prefix_len;
memcpy(ep, text, text_len);
ep[text_len] = 0; // null terminator

4
src/helpers/radiolib/RadioLibWrappers.h

@ -64,7 +64,7 @@ public:
fabsf(freq - 921.200f) < 0.05f);
}
int getMaxTextLen() const {
int getMaxTextLen() const override {
if (!isAS923_1_JP()) return 10 * 16; // default 160 bytes
uint8_t cr = getCodingRate();
if (cr <= 5) return 64; // 3874ms @ SF12/BW125/CR4-5
@ -73,7 +73,7 @@ public:
return 24; // 3547ms @ SF12/BW125/CR4-8
}
int getMaxGroupTextLen() const {
int getMaxGroupTextLen() const override {
if (!isAS923_1_JP()) return 10 * 16; // default 160 bytes
uint8_t cr = getCodingRate();
if (cr <= 5) return 64; // 3710ms @ SF12/BW125/CR4-5

Loading…
Cancel
Save