qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org, lersek@redhat.com
Subject: [Qemu-devel] [PATCH] check for available room when formatting OpenFirmware device path
Date: Mon, 23 Jul 2012 13:33:33 +0200	[thread overview]
Message-ID: <1343043213-9997-1-git-send-email-lersek@redhat.com> (raw)


Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/qdev.c |   14 +++++++++++++-
 vl.c      |    7 ++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index af54467..f1e83a4 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -502,6 +502,10 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
     if (dev && dev->parent_bus) {
         char *d;
         l = qdev_get_fw_dev_path_helper(dev->parent_bus->parent, p, size);
+        if (l >= size) {
+            return l;
+        }
+
         d = bus_get_fw_dev_path(dev->parent_bus, dev);
         if (d) {
             l += snprintf(p + l, size - l, "%s", d);
@@ -509,6 +513,10 @@ static int qdev_get_fw_dev_path_helper(DeviceState *dev, char *p, int size)
         } else {
             l += snprintf(p + l, size - l, "%s", object_get_typename(OBJECT(dev)));
         }
+
+        if (l >= size) {
+            return l;
+        }
     }
     l += snprintf(p + l , size - l, "/");
 
@@ -520,8 +528,12 @@ char* qdev_get_fw_dev_path(DeviceState *dev)
     char path[128];
     int l;
 
-    l = qdev_get_fw_dev_path_helper(dev, path, 128);
+    l = qdev_get_fw_dev_path_helper(dev, path, sizeof(path));
 
+    assert(l > 0);
+    if (l >= sizeof(path)) {
+        return NULL;
+    }
     path[l-1] = '\0';
 
     return strdup(path);
diff --git a/vl.c b/vl.c
index 8904db1..78dcc93 100644
--- a/vl.c
+++ b/vl.c
@@ -913,7 +913,12 @@ char *get_boot_devices_list(uint32_t *size)
 
         if (i->dev) {
             devpath = qdev_get_fw_dev_path(i->dev);
-            assert(devpath);
+            if (devpath == NULL) {
+                fprintf(stderr,
+                        "OpenFirmware Device Path too long (boot index %d)\n",
+                        i->bootindex);
+                exit(1);
+            }
         }
 
         if (i->suffix && devpath) {
-- 
1.7.1

             reply	other threads:[~2012-07-23 11:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-23 11:33 Laszlo Ersek [this message]
2012-07-23 12:34 ` [Qemu-devel] [PATCH] check for available room when formatting OpenFirmware device path Peter Maydell
2012-07-23 12:39   ` Peter Maydell
2012-07-23 12:46 ` Markus Armbruster
2012-07-23 13:08   ` Laszlo Ersek
2012-07-23 15:01     ` Markus Armbruster
2012-07-23 15:29       ` Laszlo Ersek
2012-07-23 15:42         ` Markus Armbruster
2012-07-25  0:19           ` [Qemu-devel] [PATCH v2 0/2] assorted device path formatting cleanups Laszlo Ersek
2012-07-25  0:19           ` [Qemu-devel] [PATCH v2 1/2] accomodate OpenFirmware device paths in sufficient storage Laszlo Ersek
2012-07-25  7:34             ` Peter Maydell
2012-07-25  8:11             ` Markus Armbruster
2012-07-25  0:19           ` [Qemu-devel] [PATCH v2 2/2] get_fw_dev_path() impls should allocate memory with glib functions Laszlo Ersek

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=1343043213-9997-1-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.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).