Skip to contentSkip to conversation

elf-loader: Add missing error handling for call of lseek

PATCH Applied Stefan Weil 3 participants 3 messages Mar 14, 2015 – Mar 19, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 elf-loader: Add missing error handling for call of lseek

This fixes a warning from Coverity.

---
 include/hw/elf_ops.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/elf_ops.h +3 -1
index 16a627b..bd71968 100644
@@ -315,7 +315,9 @@ static int glue(load_elf, SZ)(const char *name, int fd,
     glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb);
 
     size = ehdr.e_phnum * sizeof(phdr[0]);
-    lseek(fd, ehdr.e_phoff, SEEK_SET);
+    if (lseek(fd, ehdr.e_phoff, SEEK_SET) != ehdr.e_phoff) {
+        goto fail;
+    }
     phdr = g_malloc0(size);
     if (!phdr)
         goto fail;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines · On Sat, 14 Mar 2015 16:42:01 +0100 Stefan Weil <[email protected]> wrote:

This fixes a warning from Coverity.

---
 include/hw/elf_ops.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/hw/elf_ops.h +0 -0
index 16a627b..bd71968 100644

include/hw/elf_ops.h static int glue(load_elf, SZ)(const char *name, int fd, · line 323

Quoted 10 lines
include/hw/elf_ops.h +3 -1
@@ -315,7 +315,9 @@ static int glue(load_elf, SZ)(const char *name, int fd,
     glue(load_symbols, SZ)(&ehdr, fd, must_swab, clear_lsb);
 
     size = ehdr.e_phnum * sizeof(phdr[0]);
-    lseek(fd, ehdr.e_phoff, SEEK_SET);
+    if (lseek(fd, ehdr.e_phoff, SEEK_SET) != ehdr.e_phoff) {
+        goto fail;
+    }
     phdr = g_malloc0(size);
     if (!phdr)
         goto fail;

Looks good.