aboutsummaryrefslogtreecommitdiff
path: root/payloads
diff options
context:
space:
mode:
Diffstat (limited to 'payloads')
-rw-r--r--payloads/libpayload/libcbfs/cbfs.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/payloads/libpayload/libcbfs/cbfs.c b/payloads/libpayload/libcbfs/cbfs.c
index 6243473170..4dfe30a780 100644
--- a/payloads/libpayload/libcbfs/cbfs.c
+++ b/payloads/libpayload/libcbfs/cbfs.c
@@ -136,6 +136,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
/* this is a mess. There is no ntohll. */
/* for now, assume compatible byte order until we solve this. */
uint32_t entry;
+ uint32_t final_size;
if (stage == NULL)
return (void *) -1;
@@ -144,15 +145,18 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name)
name,
(uint32_t) stage->load, stage->memlen,
stage->entry);
- memset((void *) (uint32_t) stage->load, 0, stage->memlen);
- if (!cbfs_decompress(stage->compression,
- ((unsigned char *) stage) +
- sizeof(struct cbfs_stage),
- (void *) (uint32_t) stage->load,
- stage->len))
+ final_size = cbfs_decompress(stage->compression,
+ ((unsigned char *) stage) +
+ sizeof(struct cbfs_stage),
+ (void *) (uint32_t) stage->load,
+ stage->len);
+ if (!final_size)
return (void *) -1;
+ memset((void *)((uintptr_t)stage->load + final_size), 0,
+ stage->memlen - final_size);
+
DEBUG("stage loaded.\n");
entry = stage->entry;