summaryrefslogtreecommitdiffstats
path: root/src/cal.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2016-12-24 18:06:57 +0100
committerPali Rohár <pali.rohar@gmail.com>2016-12-24 18:06:57 +0100
commit117d0bb2d04df5a6cb0289f00afe61671376f0ec (patch)
treeca323c42998596c2a9dbf1504b75b6224a9016fe /src/cal.c
parentf7bad18a565515421329931acf2669c5e75a1fde (diff)
download0xFFFF-117d0bb2d04df5a6cb0289f00afe61671376f0ec.tar.bz2
cal: cal_read_block allocate memory
Diffstat (limited to 'src/cal.c')
-rw-r--r--src/cal.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/cal.c b/src/cal.c
index 8fa7e9f..25bb9ee 100644
--- a/src/cal.c
+++ b/src/cal.c
@@ -264,6 +264,7 @@ int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned lo
uint64_t filelen = cal->size;
uint8_t * data = cal->mem;
struct header * hdr;
+ void * offset;
find_offset = find_section(data, filelen, INDEX_LAST, name);
if ( find_offset < 0 )
@@ -277,12 +278,18 @@ int cal_read_block(struct cal * cal, const char * name, void ** ptr, unsigned lo
if ( crc32(0, hdr, sizeof(*hdr) - 4) != hdr->hdrsum )
return -1;
- *ptr = data + find_offset + sizeof(struct header);
- *len = hdr->length;
+ offset = data + find_offset + sizeof(struct header);
+
+ if ( crc32(0, offset, hdr->length) != hdr->datasum )
+ return -1;
- if ( crc32(0, *ptr, *len) != hdr->datasum )
+ *ptr = malloc(hdr->length);
+ if (!ptr)
return -1;
+ memcpy(*ptr, offset, hdr->length);
+ *len = hdr->length;
+
return 0;
}