[pn7160][pn7150][pn532] Fix tag purge skipping, NDEF bounds check, and NDEF length byte order (#14460)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-04 12:58:42 -05:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 9abba79c54
commit 246a8bff0c
5 changed files with 12 additions and 12 deletions
@@ -99,7 +99,7 @@ bool PN532::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_to_6
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return false;
}
@@ -134,7 +134,7 @@ bool PN532::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, nfc::NdefMessage *
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);
+3 -3
View File
@@ -562,9 +562,9 @@ optional<size_t> PN7150::find_tag_uid_(const nfc::NfcTagUid &uid) {
}
void PN7150::purge_old_tags_() {
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
this->erase_tag_(i);
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
this->erase_tag_(i - 1);
}
}
}
@@ -100,7 +100,7 @@ uint8_t PN7150::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return nfc::STATUS_FAILED;
}
@@ -135,7 +135,7 @@ uint8_t PN7150::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);
+3 -3
View File
@@ -589,9 +589,9 @@ optional<size_t> PN7160::find_tag_uid_(const nfc::NfcTagUid &uid) {
}
void PN7160::purge_old_tags_() {
for (size_t i = 0; i < this->discovered_endpoint_.size(); i++) {
if (millis() - this->discovered_endpoint_[i].last_seen > this->tag_ttl_) {
this->erase_tag_(i);
for (size_t i = this->discovered_endpoint_.size(); i > 0; i--) {
if (millis() - this->discovered_endpoint_[i - 1].last_seen > this->tag_ttl_) {
this->erase_tag_(i - 1);
}
}
}
@@ -100,7 +100,7 @@ uint8_t PN7160::find_mifare_ultralight_ndef_(const std::vector<uint8_t> &page_3_
uint8_t &message_start_index) {
const uint8_t p4_offset = nfc::MIFARE_ULTRALIGHT_PAGE_SIZE; // page 4 will begin 4 bytes into the vector
if (!(page_3_to_6.size() > p4_offset + 5)) {
if (!(page_3_to_6.size() > p4_offset + 6)) {
return nfc::STATUS_FAILED;
}
@@ -135,7 +135,7 @@ uint8_t PN7160::write_mifare_ultralight_tag_(nfc::NfcTagUid &uid, const std::sha
} else {
encoded.insert(encoded.begin() + 1, 0xFF);
encoded.insert(encoded.begin() + 2, (message_length >> 8) & 0xFF);
encoded.insert(encoded.begin() + 2, message_length & 0xFF);
encoded.insert(encoded.begin() + 3, message_length & 0xFF);
}
encoded.push_back(0xFE);