diff options
author | Li Zhijian <lizhijian@cn.fujitsu.com> | 2019-01-17 20:49:02 +0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-02-05 16:50:18 +0100 |
commit | 1f40547f5ce0c135faa7d14f066b97002fd8c204 (patch) | |
tree | 601ed8a5dc37320026b2e2bd1ff32777c801e5c3 /hw/core/loader.c | |
parent | 0c249ff71c094c0e009e2ccaef5237af3610b0fb (diff) | |
download | qemu-1f40547f5ce0c135faa7d14f066b97002fd8c204.zip qemu-1f40547f5ce0c135faa7d14f066b97002fd8c204.tar.gz qemu-1f40547f5ce0c135faa7d14f066b97002fd8c204.tar.bz2 |
hw/core/loader.c: Read as long as possible in load_image_size()
Don't expect read(2) can always read as many as it's told.
CC: Richard Henderson <richard.henderson@linaro.org>
CC: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/core/loader.c')
-rw-r--r-- | hw/core/loader.c | 11 |
1 files 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 */ |