[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/26] linux-user: Use glib malloc functions in load_
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PULL 14/26] linux-user: Use glib malloc functions in load_symbols() |
Date: |
Thu, 22 Sep 2016 15:13:34 +0300 |
From: Peter Maydell <address@hidden>
Switch to using the glib malloc functions in load_symbols();
this deals with a Coverity complaint about possible
integer overflow calculating the allocation size with
'nsyms * sizeof(*syms)'.
Signed-off-by: Peter Maydell <address@hidden>
Signed-off-by: Riku Voipio <address@hidden>
---
linux-user/elfload.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 0d07b85..3d751f8 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2111,19 +2111,19 @@ static void load_symbols(struct elfhdr *hdr, int fd,
abi_ulong load_bias)
found:
/* Now know where the strtab and symtab are. Snarf them. */
- s = malloc(sizeof(*s));
+ s = g_try_new(struct syminfo, 1);
if (!s) {
goto give_up;
}
i = shdr[str_idx].sh_size;
- s->disas_strtab = strings = malloc(i);
+ s->disas_strtab = strings = g_try_malloc(i);
if (!strings || pread(fd, strings, i, shdr[str_idx].sh_offset) != i) {
goto give_up;
}
i = shdr[sym_idx].sh_size;
- syms = malloc(i);
+ syms = g_try_malloc(i);
if (!syms || pread(fd, syms, i, shdr[sym_idx].sh_offset) != i) {
goto give_up;
}
@@ -2157,7 +2157,7 @@ static void load_symbols(struct elfhdr *hdr, int fd,
abi_ulong load_bias)
that we threw away. Whether or not this has any effect on the
memory allocation depends on the malloc implementation and how
many symbols we managed to discard. */
- new_syms = realloc(syms, nsyms * sizeof(*syms));
+ new_syms = g_try_renew(struct elf_sym, syms, nsyms);
if (new_syms == NULL) {
goto give_up;
}
@@ -2178,9 +2178,9 @@ static void load_symbols(struct elfhdr *hdr, int fd,
abi_ulong load_bias)
return;
give_up:
- free(s);
- free(strings);
- free(syms);
+ g_free(s);
+ g_free(strings);
+ g_free(syms);
}
int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
--
2.1.4
- [Qemu-devel] [PULL 05/26] linux-user: Use direct syscall for utimensat, (continued)
- [Qemu-devel] [PULL 05/26] linux-user: Use direct syscall for utimensat, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 04/26] linux-user: Implement FS_IOC_GETFLAGS and FS_IOC_SETFLAGS ioctls, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 07/26] linux-user: Range check the nfds argument to ppoll syscall, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 08/26] linux-user: report signals being taken in strace output, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 06/26] linux-user: Check for bad event numbers in epoll_wait, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 09/26] linux-user: Pass missing MAP_ANONYMOUS to target_mmap() call, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 11/26] linux-user: Fix incorrect use of host errno in do_ioctl_dm(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 10/26] linux-user: Check lock_user() return value for NULL, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 13/26] linux-user: Check dump_write() return in elf_core_dump(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 15/26] linux-user: Use correct target SHMLBA in shmat(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 14/26] linux-user: Use glib malloc functions in load_symbols(),
riku . voipio <=
- [Qemu-devel] [PULL 12/26] linux-user: Fix error handling in flatload.c target_pread(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 16/26] linux-user: ppc64: set MSR_CM bit for BookE 2.06 MMU, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 17/26] linux-user: Recheck for pending synchronous signals too, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 18/26] linux-user: Pass si_type information to queue_signal() explicitly, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 24/26] linux-user: Sanity check clone flags, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 19/26] linux-user: SIGSEGV on signal entry need not be fatal, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 20/26] linux-user: ARM: Give SIGSEGV if signal frame setup fails, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 21/26] linux-user: SIGSEGV from sigreturn need not be fatal, riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 22/26] linux-user: Implement force_sigsegv() via force_sig(), riku . voipio, 2016/09/22
- [Qemu-devel] [PULL 23/26] linux-user: Remove unnecessary nptl_flags variable from do_fork(), riku . voipio, 2016/09/22