NVS: BUGFIX non-matching type iterator works

Closes IDFGH-2229
This commit is contained in:
Jakob Hasse 2019-11-22 12:07:56 +08:00
parent de43b8406b
commit bb1cd9a440
2 changed files with 38 additions and 4 deletions

View file

@ -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;
} }

View file

@ -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]")
{ {