diff options
Diffstat (limited to 'utils/sbtools/sbtoelf.c')
-rw-r--r-- | utils/sbtools/sbtoelf.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c index 50a23e56b3..9a06eade79 100644 --- a/utils/sbtools/sbtoelf.c +++ b/utils/sbtools/sbtoelf.c | |||
@@ -71,7 +71,6 @@ char BLUE[] = { 0x1b, 0x5b, 0x31, 0x3b, '3', '4', 0x6d, '\0' }; | |||
71 | 71 | ||
72 | /* globals */ | 72 | /* globals */ |
73 | 73 | ||
74 | size_t g_sz; /* file size */ | ||
75 | uint8_t *g_buf; /* file content */ | 74 | uint8_t *g_buf; /* file content */ |
76 | #define PREFIX_SIZE 128 | 75 | #define PREFIX_SIZE 128 |
77 | char out_prefix[PREFIX_SIZE]; | 76 | char out_prefix[PREFIX_SIZE]; |
@@ -378,6 +377,14 @@ static void extract(unsigned long filesize) | |||
378 | if(sb_header->sec_hdr_size * BLOCK_SIZE != sizeof(struct sb_section_header_t)) | 377 | if(sb_header->sec_hdr_size * BLOCK_SIZE != sizeof(struct sb_section_header_t)) |
379 | bugp("Bad section header size"); | 378 | bugp("Bad section header size"); |
380 | 379 | ||
380 | if(filesize > sb_header->image_size * BLOCK_SIZE) | ||
381 | { | ||
382 | color(GREY); | ||
383 | printf("[Restrict file size from %lu to %d bytes]\n", filesize, | ||
384 | sb_header->image_size * BLOCK_SIZE); | ||
385 | filesize = sb_header->image_size * BLOCK_SIZE; | ||
386 | } | ||
387 | |||
381 | color(BLUE); | 388 | color(BLUE); |
382 | printf("Basic info:\n"); | 389 | printf("Basic info:\n"); |
383 | color(GREEN); | 390 | color(GREEN); |
@@ -763,10 +770,9 @@ int main(int argc, const char **argv) | |||
763 | 770 | ||
764 | if(fstat(fd, &st) == -1) | 771 | if(fstat(fd, &st) == -1) |
765 | bugp("firmware stat() failed"); | 772 | bugp("firmware stat() failed"); |
766 | g_sz = st.st_size; | ||
767 | 773 | ||
768 | g_buf = xmalloc(g_sz); | 774 | g_buf = xmalloc(st.st_size); |
769 | if(read(fd, g_buf, g_sz) != (ssize_t)g_sz) /* load the whole file into memory */ | 775 | if(read(fd, g_buf, st.st_size) != (ssize_t)st.st_size) /* load the whole file into memory */ |
770 | bugp("reading firmware"); | 776 | bugp("reading firmware"); |
771 | 777 | ||
772 | close(fd); | 778 | close(fd); |