@@ -51,8 +51,6 @@ namespace {
5151constexpr auto EFI_SYSTEM_TABLE_SIGNATURE =
5252 static_cast <u64 >(0x5453595320494249ULL );
5353
54- // ASCII "PE\x0\x0"
55-
5654using EfiEntry = int (*)(void *, struct EfiSystemTable *);
5755
5856template <typename T>
@@ -103,12 +101,22 @@ int load_sections_and_execute(bdev_t *dev,
103101 }
104102 memset (image_base, 0 , virtual_size);
105103 DEFER { free_pages (image_base, virtual_size / PAGE_SIZE); };
106- bio_read (dev, image_base, 0 , section_header[0 ].PointerToRawData );
104+ ssize_t bytes_reads =
105+ bio_read (dev, image_base, 0 , section_header[0 ].PointerToRawData );
106+ if (bytes_reads != section_header[0 ].SizeOfRawData ) {
107+ printf (" Failed to read section %s\n " , section_header[0 ].Name );
108+ return ERR_IO;
109+ }
107110
108111 for (size_t i = 0 ; i < sections; i++) {
109112 const auto §ion = section_header[i];
110- bio_read (dev, image_base + section.VirtualAddress , section.PointerToRawData ,
111- section.SizeOfRawData );
113+ ssize_t bytes_read =
114+ bio_read (dev, image_base + section.VirtualAddress ,
115+ section.PointerToRawData , section.SizeOfRawData );
116+ if (bytes_read != section.SizeOfRawData ) {
117+ printf (" Failed to read section %s %zu\n " , section.Name , bytes_read);
118+ return ERR_IO;
119+ }
112120 }
113121 printf (" Relocating image from 0x%llx to %p\n " , optional_header->ImageBase ,
114122 image_base);
0 commit comments