提交 3e372cf8 编写于 作者: A Aurelien Jarno

loader: don't call realloc(non_null, 0) when no symbols are present

According to C99, realloc(non_null, 0) != free(non_null), that's why
it is forbidden in QEMU.

When there are no symbols, nsyms equals to 0. Free the syms structure
and set it to NULL instead of reallocating it with a size of 0.

This fixes -kernel with stripped kernels.
Signed-off-by: NAurelien Jarno <aurelien@aurel32.net>
Acked-by: NMichael S. Tsirkin <mst@redhat.com>
上级 b430a225
......@@ -149,9 +149,14 @@ static int glue(load_symbols, SZ)(struct elfhdr *ehdr, int fd, int must_swab,
}
i++;
}
syms = qemu_realloc(syms, nsyms * sizeof(*syms));
if (nsyms) {
syms = qemu_realloc(syms, nsyms * sizeof(*syms));
qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
qsort(syms, nsyms, sizeof(*syms), glue(symcmp, SZ));
} else {
qemu_free(syms);
syms = NULL;
}
/* String table */
if (symtab->sh_link >= ehdr->e_shnum)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册