diff options
author | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 17:39:31 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-24 17:39:31 +1000 |
commit | 7bcbf364a3c2dc9645ece54820be5f54e0c84af1 (patch) | |
tree | 01f65b6fc493f2715a7b74d1762faab76799afd8 /core/nvram-format.c | |
parent | e3e38fcc77e49378db230f06b5f38e3814229aae (diff) | |
download | skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.zip skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.tar.gz skiboot-7bcbf364a3c2dc9645ece54820be5f54e0c84af1.tar.bz2 |
Expand nvram-format unit test to cover all error paths
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/nvram-format.c')
-rw-r--r-- | core/nvram-format.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/nvram-format.c b/core/nvram-format.c index 3ec0db2..fc2ddef 100644 --- a/core/nvram-format.c +++ b/core/nvram-format.c @@ -60,7 +60,7 @@ static uint8_t chrp_nv_cksum(struct chrp_nvram_hdr *hdr) return c_sum; } -void nvram_format(void *nvram_image, uint32_t nvram_size) +int nvram_format(void *nvram_image, uint32_t nvram_size) { struct chrp_nvram_hdr *h; unsigned int offset = 0; @@ -69,6 +69,8 @@ void nvram_format(void *nvram_image, uint32_t nvram_size) memset(nvram_image, 0, nvram_size); /* Create private partition */ + if (nvram_size - offset < NVRAM_SIZE_FW_PRIV) + return -1; h = nvram_image + offset; h->sig = NVRAM_SIG_FW_PRIV; h->len = NVRAM_SIZE_FW_PRIV >> 4; @@ -77,6 +79,8 @@ void nvram_format(void *nvram_image, uint32_t nvram_size) offset += NVRAM_SIZE_FW_PRIV; /* Create common partition */ + if (nvram_size - offset < NVRAM_SIZE_COMMON) + return -1; h = nvram_image + offset; h->sig = NVRAM_SIG_SYSTEM; h->len = NVRAM_SIZE_COMMON >> 4; @@ -85,11 +89,15 @@ void nvram_format(void *nvram_image, uint32_t nvram_size) offset += NVRAM_SIZE_COMMON; /* Create free space partition */ + if (nvram_size - offset < sizeof(struct chrp_nvram_hdr)) + return -1; h = nvram_image + offset; h->sig = NVRAM_SIG_FREE; h->len = (nvram_size - offset) >> 4; strncpy(h->name, NVRAM_NAME_FREE, 12); h->cksum = chrp_nv_cksum(h); + + return 0; } /* |