mirror of
https://github.com/clearlinux/graphene.git
synced 2026-10-03 15:39:36 +00:00
[LibOS] Fix a memory leak in __map_elf_object() about variable pointer new_phdr
new_phdr is allocated using malloc, if failed, it may cause unpredictable behavior on read operation, also causing resource leakage of new_phdr if read operation failed. Signed-off-by: Gary <gang1.wang@intel.com>
This commit is contained in:
@@ -404,10 +404,15 @@ call_lose:
|
||||
if (type == OBJECT_LOAD &&
|
||||
header->e_phoff + maplength <= (size_t) fbp_len) {
|
||||
ElfW(Phdr) * new_phdr = (ElfW(Phdr) *) malloc (maplength);
|
||||
if (!new_phdr) {
|
||||
errstring = "new_phdr malloc failure";
|
||||
goto call_lose;
|
||||
}
|
||||
if ((ret = (*seek) (file, header->e_phoff, SEEK_SET)) < 0 ||
|
||||
(ret = (*read) (file, new_phdr, maplength)) < 0) {
|
||||
errstring = "cannot read file data";
|
||||
errval = ret;
|
||||
free(new_phdr);
|
||||
goto call_lose;
|
||||
}
|
||||
phdr = new_phdr;
|
||||
|
||||
Reference in New Issue
Block a user