Skip to content

Commit ce99d64

Browse files
committed
Validate path length against max path size
1 parent 06ab9f7 commit ce99d64

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

examples/simple_repeater/MyMesh.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ uint8_t MyMesh::handleAnonRegionsReq(const mesh::Identity& sender, uint32_t send
151151
reply_path_hash_size = (*data >> 6) + 1;
152152
data++;
153153

154+
if (reply_path_len * reply_path_hash_size > MAX_PATH_SIZE) return 0;
154155
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
155156
// data += (uint8_t)reply_path_len * reply_path_hash_size;
156157

@@ -170,6 +171,7 @@ uint8_t MyMesh::handleAnonOwnerReq(const mesh::Identity& sender, uint32_t sender
170171
reply_path_hash_size = (*data >> 6) + 1;
171172
data++;
172173

174+
if (reply_path_len * reply_path_hash_size > MAX_PATH_SIZE) return 0;
173175
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
174176
// data += (uint8_t)reply_path_len * reply_path_hash_size;
175177

@@ -190,6 +192,7 @@ uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender
190192
reply_path_hash_size = (*data >> 6) + 1;
191193
data++;
192194

195+
if (reply_path_len * reply_path_hash_size > MAX_PATH_SIZE) return 0;
193196
memcpy(reply_path, data, ((uint8_t)reply_path_len) * reply_path_hash_size);
194197
// data += (uint8_t)reply_path_len * reply_path_hash_size;
195198

src/Packet.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ size_t Packet::writePath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
2222
uint8_t hash_size = (path_len >> 6) + 1;
2323
size_t len = hash_count*hash_size;
2424
if (len > MAX_PATH_SIZE) {
25-
MESH_DEBUG_PRINTLN("Packet::copyPath, invalid path_len=%d", (uint32_t)path_len);
25+
MESH_DEBUG_PRINTLN("Packet::writePath, invalid path_len=%d", (uint32_t)path_len);
2626
return 0; // Error
2727
}
2828
memcpy(dest, src, len);
2929
return len;
3030
}
3131

3232
uint8_t Packet::copyPath(uint8_t* dest, const uint8_t* src, uint8_t path_len) {
33-
writePath(dest, src, path_len);
33+
if (writePath(dest, src, path_len) == 0 && (path_len & 63) != 0) {
34+
return 0; // Error: writePath failed for non-empty path
35+
}
3436
return path_len;
3537
}
3638

0 commit comments

Comments
 (0)