BigW Consortium Gitlab

Commit c1e98362 by rmilecki

nvram: fix "Segmentation fault" caused by setting memory out of buffer

Some MTD partitions with NVRAM have content starting in the middle. In such case offset is set and nvram_header returns pointer to the middle. It means we have to respect offset when calculating remaining space. By the way use real MTD partition size (nvram_part_size variable) as we may want to bump NVRAM_SPACE in the (very near) future. Signed-off-by: 's avatarRafał Miłecki <zajec5@gmail.com> Backport of r46251 git-svn-id: svn://svn.openwrt.org/openwrt/branches/chaos_calmer@46258 3c298f89-4303-0410-b956-a3cf2f4a3e73
parent dbde9080
......@@ -286,11 +286,11 @@ int nvram_commit(nvram_handle_t *h)
/* Clear data area */
ptr = (char *) header + sizeof(nvram_header_t);
memset(ptr, 0xFF, NVRAM_SPACE - sizeof(nvram_header_t));
memset(ptr, 0xFF, nvram_part_size - h->offset - sizeof(nvram_header_t));
memset(&tmp, 0, sizeof(nvram_header_t));
/* Leave space for a double NUL at the end */
end = (char *) header + NVRAM_SPACE - 2;
end = (char *) header + nvram_part_size - h->offset - 2;
/* Write out all tuples */
for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment