[syslinux:elflink] module: Check the return value of malloc()

syslinux-bot for Matt Fleming matt.fleming at intel.com
Wed Jan 23 07:09:10 PST 2013


Commit-ID:  cd079794e8908b9402840cde322bbd32ae08523c
Gitweb:     http://www.syslinux.org/commit/cd079794e8908b9402840cde322bbd32ae08523c
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 17 Jan 2013 14:50:29 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Wed, 23 Jan 2013 15:05:28 +0000

module: Check the return value of malloc()

Instead of blindly writing through a possible-NULL pointer, check the
return value of malloc().

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/lib/sys/module/elf_module.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 24da220..c4e9d41 100644
--- a/com32/lib/sys/module/elf_module.c
+++ b/com32/lib/sys/module/elf_module.c
@@ -67,6 +67,9 @@ static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 
 	// Load the PHT
 	pht = malloc(elf_hdr->e_phnum * elf_hdr->e_phentsize);
+	if (!pht)
+		return -1;
+
 	image_read(pht, elf_hdr->e_phnum * elf_hdr->e_phentsize, module);
 
 	// Compute the memory needings of the module
@@ -170,6 +173,11 @@ static int load_segments(struct elf_module *module, Elf32_Ehdr *elf_hdr) {
 
 	// Load the SHT
 	sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize);
+	if (!sht) {
+		res = -1;
+		goto out;
+	}
+
 	image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module);
 
 	// Setup the symtable size


More information about the Syslinux-commits mailing list