Skip to content

Commit e3526d0

Browse files
FlyGoatbibo-mao
authored andcommitted
hw/core/loader: Use ssize_t for efi zboot unpacker
Convert to use sszie_t to represent size internally to avoid large image overflowing the size. Suggested-by: Richard Henderson <[email protected]> Signed-off-by: Jiaxun Yang <[email protected]> Signed-off-by: Bibo Mao <[email protected]> Reviewed-by: Bibo Mao <[email protected]>
1 parent 3f8bcbb commit e3526d0

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

hw/arm/boot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base,
857857
hwaddr kernel_load_offset = KERNEL64_LOAD_ADDR;
858858
uint64_t kernel_size = 0;
859859
uint8_t *buffer;
860-
int size;
860+
ssize_t size;
861861

862862
/* On aarch64, it's the bootloader's job to uncompress the kernel. */
863863
size = load_image_gzipped_buffer(filename, LOAD_IMAGE_MAX_GUNZIP_BYTES,

hw/core/loader.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,11 @@ struct linux_efi_zboot_header {
886886
*
887887
* If the image is not a Linux EFI zboot image, do nothing and return success.
888888
*/
889-
ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size)
889+
ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size)
890890
{
891891
const struct linux_efi_zboot_header *header;
892892
uint8_t *data = NULL;
893-
int ploff, plsize;
893+
ssize_t ploff, plsize;
894894
ssize_t bytes;
895895

896896
/* ignore if this is too small to be a EFI zboot image */

include/hw/loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ ssize_t load_image_gzipped_buffer(const char *filename, uint64_t max_sz,
101101
* Returns the size of the decompressed payload if decompression was performed
102102
* successfully.
103103
*/
104-
ssize_t unpack_efi_zboot_image(uint8_t **buffer, int *size);
104+
ssize_t unpack_efi_zboot_image(uint8_t **buffer, ssize_t *size);
105105

106106
#define ELF_LOAD_FAILED -1
107107
#define ELF_LOAD_NOT_ELF -2

0 commit comments

Comments
 (0)