From patchwork Mon Jul 23 11:33:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 172631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D58A02C0354 for ; Mon, 23 Jul 2012 21:32:38 +1000 (EST) Received: from localhost ([::1]:45302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StGsO-0008Ry-Rn for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 07:32:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StGsC-0008R5-SJ for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:32:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StGsB-0003i5-7E for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:32:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StGsA-0003h1-WD for qemu-devel@nongnu.org; Mon, 23 Jul 2012 07:32:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6NBWL6r002867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 23 Jul 2012 07:32:21 -0400 Received: from lacos-laptop.usersys.redhat.com (vpn1-7-215.ams2.redhat.com [10.36.7.215]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q6NBWKQm004486; Mon, 23 Jul 2012 07:32:20 -0400 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Date: Mon, 23 Jul 2012 13:33:33 +0200 Message-Id: <1343043213-9997-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] check for available room when formatting OpenFirmware device path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Laszlo Ersek --- 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) {