NVS: BUGFIX non-matching type iterator works
Closes IDFGH-2229
This commit is contained in:
parent
de43b8406b
commit
bb1cd9a440
2 changed files with 38 additions and 4 deletions
|
@ -622,9 +622,9 @@ esp_err_t Page::mLoadEntryTable()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note that logic for duplicate detections works fine even
|
/* Note that logic for duplicate detections works fine even
|
||||||
* when old-format blob is present along with new-format blob-index
|
* when old-format blob is present along with new-format blob-index
|
||||||
* for same key on active page. Since datatype is not used in hash calculation,
|
* for same key on active page. Since datatype is not used in hash calculation,
|
||||||
* old-format blob will be removed.*/
|
* old-format blob will be removed.*/
|
||||||
if (duplicateIndex < i) {
|
if (duplicateIndex < i) {
|
||||||
eraseEntryAndSpan(duplicateIndex);
|
eraseEntryAndSpan(duplicateIndex);
|
||||||
|
@ -864,6 +864,7 @@ esp_err_t Page::findItem(uint8_t nsIndex, ItemType datatype, const char* key, si
|
||||||
if (key == nullptr && nsIndex == NS_ANY && chunkIdx == CHUNK_ANY) {
|
if (key == nullptr && nsIndex == NS_ANY && chunkIdx == CHUNK_ANY) {
|
||||||
continue; // continue for bruteforce search on blob indices.
|
continue; // continue for bruteforce search on blob indices.
|
||||||
}
|
}
|
||||||
|
itemIndex = i;
|
||||||
return ESP_ERR_NVS_TYPE_MISMATCH;
|
return ESP_ERR_NVS_TYPE_MISMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -772,6 +772,39 @@ TEST_CASE("nvs iterators tests", "[nvs]")
|
||||||
nvs_close(handle_2);
|
nvs_close(handle_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Iterator with not matching type iterates correctly", "[nvs]")
|
||||||
|
{
|
||||||
|
SpiFlashEmulator emu(5);
|
||||||
|
nvs_iterator_t it;
|
||||||
|
nvs_handle_t my_handle;
|
||||||
|
const char* NAMESPACE = "test_ns_4";
|
||||||
|
|
||||||
|
const uint32_t NVS_FLASH_SECTOR = 0;
|
||||||
|
const uint32_t NVS_FLASH_SECTOR_COUNT_MIN = 5;
|
||||||
|
emu.setBounds(NVS_FLASH_SECTOR, NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN);
|
||||||
|
|
||||||
|
for (uint16_t i = NVS_FLASH_SECTOR; i < NVS_FLASH_SECTOR + NVS_FLASH_SECTOR_COUNT_MIN; ++i) {
|
||||||
|
spi_flash_erase_sector(i);
|
||||||
|
}
|
||||||
|
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
||||||
|
|
||||||
|
// writing string to namespace (a type which spans multiple entries)
|
||||||
|
TEST_ESP_OK(nvs_open(NAMESPACE, NVS_READWRITE, &my_handle));
|
||||||
|
TEST_ESP_OK(nvs_set_str(my_handle, "test-string", "InitString0"));
|
||||||
|
TEST_ESP_OK(nvs_commit(my_handle));
|
||||||
|
nvs_close(my_handle);
|
||||||
|
|
||||||
|
it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_I32);
|
||||||
|
CHECK(it == NULL);
|
||||||
|
|
||||||
|
// re-init to trigger cleaning up of broken items -> a corrupted string will be erased
|
||||||
|
nvs_flash_deinit();
|
||||||
|
TEST_ESP_OK(nvs_flash_init_custom(NVS_DEFAULT_PART_NAME, NVS_FLASH_SECTOR, NVS_FLASH_SECTOR_COUNT_MIN));
|
||||||
|
|
||||||
|
it = nvs_entry_find(NVS_DEFAULT_PART_NAME, NAMESPACE, NVS_TYPE_STR);
|
||||||
|
CHECK(it != NULL);
|
||||||
|
nvs_release_iterator(it);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE("wifi test", "[nvs]")
|
TEST_CASE("wifi test", "[nvs]")
|
||||||
{
|
{
|
||||||
|
@ -1955,7 +1988,7 @@ TEST_CASE("Multi-page blob erased using nvs_erase_key should not be found when p
|
||||||
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle));
|
TEST_ESP_OK(nvs_open("Test", NVS_READWRITE, &handle));
|
||||||
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
|
TEST_ESP_OK(nvs_set_blob(handle, "abc", blob, blob_size));
|
||||||
TEST_ESP_OK(nvs_erase_key(handle, "abc"));
|
TEST_ESP_OK(nvs_erase_key(handle, "abc"));
|
||||||
TEST_ESP_ERR(nvs_get_blob(handle, "abc", NULL, &read_size), ESP_ERR_NVS_NOT_FOUND);
|
TEST_ESP_ERR(nvs_get_blob(handle, "abc", NULL, &read_size), ESP_ERR_NVS_NOT_FOUND);
|
||||||
TEST_ESP_OK(nvs_commit(handle));
|
TEST_ESP_OK(nvs_commit(handle));
|
||||||
nvs_close(handle);
|
nvs_close(handle);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue