[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 46/49] hw/core/loader.c: Read as long as possible in
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 46/49] hw/core/loader.c: Read as long as possible in load_image_size() |
Date: |
Mon, 21 Jan 2019 19:06:17 +0100 |
From: Li Zhijian <address@hidden>
Don't expect read(2) can always read as many as it's told.
CC: Richard Henderson <address@hidden>
CC: Stefano Garzarella <address@hidden>
Signed-off-by: Li Zhijian <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
Reviewed-by: Stefano Garzarella <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/core/loader.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 3a000d5..fe5cb24 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -77,21 +77,20 @@ int64_t get_image_size(const char *filename)
ssize_t load_image_size(const char *filename, void *addr, size_t size)
{
int fd;
- ssize_t actsize;
+ ssize_t actsize, l = 0;
fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0) {
return -1;
}
- actsize = read(fd, addr, size);
- if (actsize < 0) {
- close(fd);
- return -1;
+ while ((actsize = read(fd, addr + l, size - l)) > 0) {
+ l += actsize;
}
+
close(fd);
- return actsize;
+ return actsize < 0 ? -1 : l;
}
/* read()-like version */
--
1.8.3.1
- [Qemu-devel] [PULL 35/49] target-i386: hvf: remove MPX support, (continued)
- [Qemu-devel] [PULL 35/49] target-i386: hvf: remove MPX support, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 37/49] contrib/elf2dmp: use GLib in ELF processing, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 02/49] include: update Linux headers to 4.21-rc1/5.0-rc1, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 29/49] linuxboot_dma: move common functions in a new header, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 33/49] i386: remove the 'INTEL_PT' CPUID bit from named CPU models, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 42/49] monitor: do not use QTAILQ_FOREACH_SAFE across critical sections, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 43/49] crypto: finish removing TABs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 44/49] ui: vnc: finish removing TABs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 47/49] i386: import & use bootparam.h, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 48/49] i386: allow to load initrd below 4 GB for recent linux, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 46/49] hw/core/loader.c: Read as long as possible in load_image_size(),
Paolo Bonzini <=
- [Qemu-devel] [PULL 45/49] unify len and addr type for memory/address APIs, Paolo Bonzini, 2019/01/21
- [Qemu-devel] [PULL 49/49] docker: disable Xen on CentOS 7, Paolo Bonzini, 2019/01/21
- Re: [Qemu-devel] [PULL 00/49] Misc patches for 2019-01-21, Peter Maydell, 2019/01/22