qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hollis Blanchard <hollisb@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Hollis Blanchard <hollisb@us.ibm.com>
Subject: [Qemu-devel] [PATCH 1/5] uImage: don't leak file data or file descriptor
Date: Thu, 20 Nov 2008 13:34:38 -0600	[thread overview]
Message-ID: <c1153df10703669572fedd831c752d248df330cb.1227209336.git.hollisb@us.ibm.com> (raw)
In-Reply-To: <1227209682-28842-1-git-send-email-hollisb@us.ibm.com>

Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
---
Changes from v1:
- Combine the failure and success return paths to avoid leaking the file
  descriptor as well.
---
 loader.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/loader.c b/loader.c
index 8722909..e7e6abc 100644
--- a/loader.c
+++ b/loader.c
@@ -354,6 +354,7 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
     uboot_image_header_t h;
     uboot_image_header_t *hdr = &h;
     uint8_t *data = NULL;
+    int ret = -1;
 
     fd = open(filename, O_RDONLY | O_BINARY);
     if (fd < 0)
@@ -361,23 +362,23 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
 
     size = read(fd, hdr, sizeof(uboot_image_header_t));
     if (size < 0)
-        goto fail;
+        goto out;
 
     bswap_uboot_header(hdr);
 
     if (hdr->ih_magic != IH_MAGIC)
-        goto fail;
+        goto out;
 
     /* TODO: Implement Multi-File images.  */
     if (hdr->ih_type == IH_TYPE_MULTI) {
         fprintf(stderr, "Unable to load multi-file u-boot images\n");
-        goto fail;
+        goto out;
     }
 
     /* TODO: Implement compressed images.  */
     if (hdr->ih_comp != IH_COMP_NONE) {
         fprintf(stderr, "Unable to load compressed u-boot images\n");
-        goto fail;
+        goto out;
     }
 
     /* TODO: Check CPU type.  */
@@ -391,20 +392,20 @@ int load_uboot(const char *filename, target_ulong *ep, int *is_linux)
     *ep = hdr->ih_ep;
     data = qemu_malloc(hdr->ih_size);
     if (!data)
-        goto fail;
+        goto out;
 
     if (read(fd, data, hdr->ih_size) != hdr->ih_size) {
         fprintf(stderr, "Error reading file\n");
-        goto fail;
+        goto out;
     }
 
     cpu_physical_memory_write_rom(hdr->ih_load, data, hdr->ih_size);
 
-    return hdr->ih_size;
+    ret = hdr->ih_size;
 
-fail:
+out:
     if (data)
         qemu_free(data);
     close(fd);
-    return -1;
+    return ret;
 }
-- 
1.5.6.5

  reply	other threads:[~2008-11-20 19:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-20 19:34 [Qemu-devel] [v2] improvements in uImage loading Hollis Blanchard
2008-11-20 19:34 ` Hollis Blanchard [this message]
2008-11-20 19:34   ` [Qemu-devel] [PATCH 2/5] uImage: implement gzip support Hollis Blanchard
2008-11-20 19:34   ` [Qemu-devel] [PATCH 3/5] uImage: return base load address Hollis Blanchard
2008-11-20 22:05     ` Anthony Liguori
2008-11-20 22:13       ` Hollis Blanchard
2008-11-20 19:34   ` [Qemu-devel] [PATCH 4/5] uImage: rename load_uboot() to load_uimage() Hollis Blanchard
2008-11-20 19:34   ` [Qemu-devel] [PATCH 5/5] uImage: only try to load 'kernel' images Hollis Blanchard
2008-11-20 20:27 ` [Qemu-devel] [v2] improvements in uImage loading Jean-Christophe PLAGNIOL-VILLARD
2008-11-20 22:15 ` Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1153df10703669572fedd831c752d248df330cb.1227209336.git.hollisb@us.ibm.com \
    --to=hollisb@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).