-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Router::allocForSending: null-check packet pool allocation #10261
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
base: develop
Are you sure you want to change the base?
Changes from all commits
6a77c93
931f2ed
43bb584
ac1dddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,6 +189,10 @@ inline void onReceiveJson(byte *payload, size_t length) | |
|
|
||
| // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh | ||
| meshtastic_MeshPacket *p = router->allocForSending(); | ||
| if (!p) { | ||
| LOG_WARN("MQTT downlink sendtext dropped: packet pool exhausted"); | ||
| return; | ||
| } | ||
|
Comment on lines
191
to
+195
|
||
| p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; | ||
| if (json.find("channel") != json.end() && json["channel"]->IsNumber() && | ||
| (json["channel"]->AsNumber() < channels.getNumChannels())) | ||
|
|
@@ -202,7 +206,11 @@ inline void onReceiveJson(byte *payload, size_t length) | |
| p->decoded.payload.size = jsonPayloadStr.length(); | ||
| service->sendToMesh(p, RX_SRC_LOCAL); | ||
| } else { | ||
| // Release the allocated packet back to the pool — `p` would otherwise leak, | ||
| // permanently reducing the number of available slots for every future | ||
| // send attempt. | ||
| LOG_WARN("Received MQTT json payload too long, drop"); | ||
| packetPool.release(p); | ||
| } | ||
| } else if (json["type"]->AsString().compare("sendposition") == 0 && json["payload"]->IsObject()) { | ||
| // invent the "sendposition" type for a valid envelope | ||
|
|
@@ -220,6 +228,10 @@ inline void onReceiveJson(byte *payload, size_t length) | |
|
|
||
| // construct protobuf data packet using POSITION, send it to the mesh | ||
| meshtastic_MeshPacket *p = router->allocForSending(); | ||
| if (!p) { | ||
| LOG_WARN("MQTT downlink sendposition dropped: packet pool exhausted"); | ||
| return; | ||
| } | ||
| p->decoded.portnum = meshtastic_PortNum_POSITION_APP; | ||
| if (json.find("channel") != json.end() && json["channel"]->IsNumber() && | ||
| (json["channel"]->AsNumber() < channels.getNumChannels())) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allocDataPacket()can now returnnullptrwhen the packet pool is exhausted. Many existing callers (includingProtobufModule::allocDataProtobuf()and several modules that callallocDataPacket()directly) assume a non-null return and will still dereference the pointer, so the pool-exhaustion crash is not fully addressed. Either update the common helper(s) to propagate/handle nullptr safely (e.g., makeallocDataProtobuf()return nullptr when allocation fails) and/or update call sites to check for nullptr before dereferencing.