[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 7/8] linux-user: Use glib malloc functions in load_s
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PATCH 7/8] linux-user: Use glib malloc functions in load_symbols() |
Date: |
Tue, 12 Jul 2016 13:02:18 +0100 |
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>
---
I opted to use the _try_ versions rather than switching
to the abort-on-failure allocation functions because
(a) the handle-failure code is already in place and correct
(b) loading symbols from the ELF file is debug-only and
can safely be skipped
---
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 7c46cfb..b062199 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)
--
1.9.1
- [Qemu-devel] [PATCH 0/8] linux-user: fix various coverity nits, Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 1/8] linux-user: Pass missing MAP_ANONYMOUS to target_mmap() call, Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 2/8] linux-user: Check lock_user() return value for NULL, Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 5/8] linux-user: Don't write off end of new_utsname buffer, Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 7/8] linux-user: Use glib malloc functions in load_symbols(),
Peter Maydell <=
- [Qemu-devel] [PATCH 6/8] linux-user: Check dump_write() return in elf_core_dump(), Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 4/8] linux-user: Fix error handling in flatload.c target_pread(), Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 3/8] linux-user: Fix incorrect use of host errno in do_ioctl_dm(), Peter Maydell, 2016/07/12
- [Qemu-devel] [PATCH 8/8] linux-user: Fix memchr() argument in open_self_cmdline(), Peter Maydell, 2016/07/12
- Re: [Qemu-devel] [PATCH 0/8] linux-user: fix various coverity nits, Paolo Bonzini, 2016/07/12