From patchwork Sun Oct 17 18:43:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 68091 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 02BC6B70F3 for ; Mon, 18 Oct 2010 05:52:42 +1100 (EST) Received: from localhost ([127.0.0.1]:42218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7YLX-00076q-EP for incoming@patchwork.ozlabs.org; Sun, 17 Oct 2010 14:52:39 -0400 Received: from [140.186.70.92] (port=51620 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P7YIz-00064r-Jg for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:50:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P7YIw-0003nh-Ta for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:50:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P7YIw-0003nX-Mc for qemu-devel@nongnu.org; Sun, 17 Oct 2010 14:49:58 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9HInvuf022670 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Oct 2010 14:49:57 -0400 Received: from redhat.com (vpn2-8-167.ams2.redhat.com [10.36.8.167]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o9HIntW0028518; Sun, 17 Oct 2010 14:49:56 -0400 Date: Sun, 17 Oct 2010 20:43:40 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Alex Williamson Message-ID: <20101017184340.GA12524@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH] migration: don't segfault on invalid input X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org host_from_stream_offset returns NULL on error, return error instead of trying to use that address, to avoid segfault on invalid stream. Signed-off-by: Michael S. Tsirkin --- arch_init.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/arch_init.c b/arch_init.c index e468c0c..bc7528d 100644 --- a/arch_init.c +++ b/arch_init.c @@ -116,6 +116,8 @@ static int ram_save_block(QEMUFile *f) if (!block) block = QLIST_FIRST(&ram_list.blocks); + if (!last_block) + last_block = block; current_addr = block->offset + offset; @@ -390,6 +392,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) host = qemu_get_ram_ptr(addr); else host = host_from_stream_offset(f, addr, flags); + if (!host) { + return -EINVAL; + } ch = qemu_get_byte(f); memset(host, ch, TARGET_PAGE_SIZE);