aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2013-01-17 14:50:29 +0000
committerMatt Fleming <matt.fleming@intel.com>2013-01-23 15:05:28 +0000
commitcd079794e8908b9402840cde322bbd32ae08523c (patch)
tree4363681f85e3f9f7ecc1d39c7fbcacc951e3b3c0
parent13fb5e172fbfac9e1afeba55102b1eb535cf1d4a (diff)
downloadsyslinux-cd079794e8908b9402840cde322bbd32ae08523c.tar.gz
syslinux-cd079794e8908b9402840cde322bbd32ae08523c.tar.xz
syslinux-cd079794e8908b9402840cde322bbd32ae08523c.zip
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@intel.com>
-rw-r--r--com32/lib/sys/module/elf_module.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c
index 24da2209..c4e9d410 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