Changeset 46251


Ignore:
Timestamp:
2015-07-07T23:21:49+02:00 (3 years ago)
Author:
rmilecki
Message:

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: Rafał Miłecki <zajec5@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/utils/nvram/src/nvram.c

    r45578 r46251  
    287287        /* Clear data area */ 
    288288        ptr = (char *) header + sizeof(nvram_header_t); 
    289         memset(ptr, 0xFF, NVRAM_SPACE - sizeof(nvram_header_t)); 
     289        memset(ptr, 0xFF, nvram_part_size - h->offset - sizeof(nvram_header_t)); 
    290290        memset(&tmp, 0, sizeof(nvram_header_t)); 
    291291 
    292292        /* Leave space for a double NUL at the end */ 
    293         end = (char *) header + NVRAM_SPACE - 2; 
     293        end = (char *) header + nvram_part_size - h->offset - 2; 
    294294 
    295295        /* Write out all tuples */ 
Note: See TracChangeset for help on using the changeset viewer.