lf sim: better to return err on faulty offset, thanks @iceman

This commit is contained in:
Philippe Teuwen 2020-04-29 20:07:04 +02:00
commit 1410d4d9b5

View file

@ -1654,14 +1654,16 @@ static void PacketReceived(PacketCommandNG *packet) {
} }
// offset should not be over buffer // offset should not be over buffer
uint16_t offset = MIN(BIGBUF_SIZE - 1, payload->offset); if (payload->offset >= BIGBUF_SIZE) {
reply_ng(CMD_LF_UPLOAD_SIM_SAMPLES, PM3_EOVFLOW, NULL, 0);
break;
}
// ensure len bytes copied wont go past end of bigbuf // ensure len bytes copied wont go past end of bigbuf
uint16_t len = MIN(BIGBUF_SIZE - offset, sizeof(payload->data)); uint16_t len = MIN(BIGBUF_SIZE - payload->offset, sizeof(payload->data));
uint8_t *mem = BigBuf_get_addr(); uint8_t *mem = BigBuf_get_addr();
memcpy(mem + offset, &payload->data, len); memcpy(mem + payload->offset, &payload->data, len);
reply_ng(CMD_LF_UPLOAD_SIM_SAMPLES, PM3_SUCCESS, NULL, 0); reply_ng(CMD_LF_UPLOAD_SIM_SAMPLES, PM3_SUCCESS, NULL, 0);
break; break;
} }