diff mbox

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

Message ID 1426347721-8349-1-git-send-email-sw@weilnetz.de
State Accepted
Headers show

Commit Message

Stefan Weil March 14, 2015, 3:42 p.m. UTC
This fixes a warning from Coverity.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 include/hw/elf_ops.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Thomas Huth March 16, 2015, 10:02 a.m. UTC | #1
On Sat, 14 Mar 2015 16:42:01 +0100
Stefan Weil <sw@weilnetz.de> wrote:

> This fixes a warning from Coverity.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  include/hw/elf_ops.h |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index 16a627b..bd71968 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -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.

Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
Michael Tokarev March 19, 2015, 8:38 a.m. UTC | #2
Applied to trivial, thanks!

/mjt
diff mbox

Patch

diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 16a627b..bd71968 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -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;