Repeater, room server, sensor: fix CLI reply buffer overflow, OTA bounds checks, and ACL slot rotation
This commit is contained in:
1 parent
e9501d0437
commit
5a83c230cd
5 files changed
+15
-11
No files matched your search
@@ -63,9 +63,10 @@ void ClientACL::load(FILESYSTEM* fs, const mesh::LocalIdentity& self_id) {
|
||||
#define ACL_TS_RECORD (ACL_TS_PREFIX + 4)
|
||||
|
||||
static const char* tsFilename(uint8_t slot) { return slot ? "/s_acl_ts1" : "/s_acl_ts0"; }
|
||||
static uint8_t s_ts_buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
|
||||
void ClientACL::loadTimestamps() {
|
||||
static uint8_t buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
uint8_t* buf = s_ts_buf;
|
||||
_num_ts_orphans = 0;
|
||||
_ts_seq = 0;
|
||||
_ts_slot = 0;
|
||||
@@ -78,7 +79,7 @@ void ClientACL::loadTimestamps() {
|
||||
File file = _fs->open(tsFilename(slot));
|
||||
#endif
|
||||
if (!file) continue;
|
||||
int len = file.read(buf, sizeof(buf));
|
||||
int len = file.read(buf, sizeof(s_ts_buf));
|
||||
file.close();
|
||||
if (len < 8 || (len - 8) % ACL_TS_RECORD != 0) continue;
|
||||
|
||||
@@ -121,7 +122,7 @@ void ClientACL::loadTimestamps() {
|
||||
|
||||
void ClientACL::saveTimestamps() {
|
||||
if (!_fs) return;
|
||||
static uint8_t buf[2 * MAX_CLIENTS * ACL_TS_RECORD + 8];
|
||||
uint8_t* buf = s_ts_buf;
|
||||
int len = 0;
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
if (clients[i].saved_timestamp == 0) continue;
|
||||
@@ -142,10 +143,10 @@ void ClientACL::saveTimestamps() {
|
||||
|
||||
File file = openWrite(_fs, tsFilename(_ts_slot));
|
||||
if (file) {
|
||||
file.write(buf, len);
|
||||
size_t written = file.write(buf, len);
|
||||
file.close();
|
||||
if (written == (size_t)len) _ts_slot ^= 1;
|
||||
}
|
||||
_ts_slot ^= 1;
|
||||
}
|
||||
|
||||
void ClientACL::orphanTimestamp(const ClientInfo* c) {
|
||||
|
||||
@@ -62,7 +62,7 @@ static int in_shift_phase(void) {
|
||||
static int cb_read(void *arg, void *dst, uintptr_t src, size_t size) {
|
||||
fwp_job *j = (fwp_job *)arg;
|
||||
uint8_t *d = (uint8_t *)dst;
|
||||
if (src + size > j->mem_size) return j->err = FWP_ERR_ARGS;
|
||||
if (src > j->mem_size || size > j->mem_size - src) return j->err = FWP_ERR_ARGS;
|
||||
if (!in_shift_phase() && src < j->written_end) return j->err = FWP_ERR_OVERREAD;
|
||||
while (size > 0) {
|
||||
uintptr_t a = src;
|
||||
@@ -106,7 +106,7 @@ static int cb_erase(void *arg, uintptr_t addr, size_t size) {
|
||||
|
||||
static int cb_write(void *arg, uintptr_t dst, void *src, size_t size) {
|
||||
fwp_job *j = (fwp_job *)arg;
|
||||
if (j->page_addr == NO_PAGE || dst < j->page_addr || dst + size > j->page_addr + FWP_PAGE)
|
||||
if (j->page_addr == NO_PAGE || dst < j->page_addr || size > FWP_PAGE - (dst - j->page_addr))
|
||||
return j->err = FWP_ERR_ORDER;
|
||||
fwp_copy(&g_page[dst - j->page_addr], (const uint8_t *)src, (uint32_t)size);
|
||||
if (j->dry && !in_shift_phase()) j->sink(j->sink_ctx, (const uint8_t *)src, (uint32_t)size);
|
||||
|
||||
@@ -743,9 +743,9 @@ void FwUpdate::cmdBegin(uint32_t sender_timestamp, const char *arg, char *reply)
|
||||
strcpy(reply, "ERR: fw begin <bytes>");
|
||||
return;
|
||||
}
|
||||
if (stage + total > FW_OTA_STAGE_END) {
|
||||
if (stage >= FW_OTA_STAGE_END || total > FW_OTA_STAGE_END - stage) {
|
||||
sprintf(reply, "ERR: %lu B does not fit, %lu free", (unsigned long)total,
|
||||
(unsigned long)(FW_OTA_STAGE_END - stage));
|
||||
(unsigned long)(stage < FW_OTA_STAGE_END ? FW_OTA_STAGE_END - stage : 0));
|
||||
return;
|
||||
}
|
||||
_stage = stage;
|
||||
@@ -975,6 +975,7 @@ void FwUpdate::cmdApply(uint32_t sender_timestamp, const char *arg, char *reply)
|
||||
_apply_force = force;
|
||||
_apply_err[0] = 0;
|
||||
_apply_at = millis() + 2000; // let the reply go out first
|
||||
if (_apply_at == 0) _apply_at = 1;
|
||||
sprintf(reply, "OK applying %s in 2 s (batt %umV%s), back in ~20 s", _version, mv,
|
||||
_board.isExternalPowered() ? ", USB" : "");
|
||||
}
|
||||
|
||||
@@ -323,6 +323,7 @@ bool NodeMaintenance::dfuCommand(uint32_t sender_timestamp, const char* command,
|
||||
return true;
|
||||
}
|
||||
_dfu_at = millis() + 700;
|
||||
if (_dfu_at == 0) _dfu_at = 1;
|
||||
_dfu_mode = (strcmp(arg, "serial") == 0) ? 1 : (strcmp(arg, "ota") == 0 ? 2 : 0);
|
||||
#else
|
||||
strcpy(reply, "ERR: not an nRF52 board");
|
||||
|
||||
Reference in new issue
Block a user