From patchwork Mon Oct 13 14:36:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Gang X-Patchwork-Id: 399215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 848E71400DD for ; Tue, 14 Oct 2014 01:31:09 +1100 (EST) Received: from localhost ([::1]:33819 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdgeQ-00011W-5n for incoming@patchwork.ozlabs.org; Mon, 13 Oct 2014 10:31:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xdge1-0000kX-7M for qemu-devel@nongnu.org; Mon, 13 Oct 2014 10:30:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xdgds-0000uB-0j for qemu-devel@nongnu.org; Mon, 13 Oct 2014 10:30:41 -0400 Received: from mail-pd0-x22a.google.com ([2607:f8b0:400e:c02::22a]:50991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XdgdY-0000mR-K7; Mon, 13 Oct 2014 10:30:12 -0400 Received: by mail-pd0-f170.google.com with SMTP id p10so5773968pdj.29 for ; Mon, 13 Oct 2014 07:30:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :content-type:content-transfer-encoding; bh=ZKb6NS/f3f2ZX5lW4rKieVEFjFU8T8nYm9U5gHcyXK0=; b=G7j2sk8tlOfdmOZMQUhtXD7POmYh7hPqXQsZpbwni5KWg/svvVcjz+7c7iJgi+j3Dg Lbyt9GmRdrB8dAvnD/rDyQ5PVz5OWdcQvnWOOk00AewPY9LN41WUc8cYIh4clIkVx5mY tErw4LeS+APKDYGNSvGyBL1wQc116zHJOmecO9Znwzc5euflBhI74ZaUdsQGOm+gOA3g z2ZYKa2W6/1CNY/PVa/8smDTPRPMiR7rxGvPuIEu5Wnza7tPTB9h/N/Qym2giXweO+aa kZ4oAUeGnIoOS/1XIT/hT91MWz7K9zvNbeDGMJvkgxoC9m6T19B0w87tWMO4/MNmHuCt v6aA== X-Received: by 10.68.163.164 with SMTP id yj4mr2408327pbb.142.1413210610527; Mon, 13 Oct 2014 07:30:10 -0700 (PDT) Received: from ShengShiZhuChengdeMacBook-Pro.local ([223.72.65.118]) by mx.google.com with ESMTPSA id ot8sm11442840pbc.1.2014.10.13.07.30.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2014 07:30:09 -0700 (PDT) Message-ID: <543BE352.3080609@gmail.com> Date: Mon, 13 Oct 2014 22:36:02 +0800 From: Chen Gang User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 MIME-Version: 1.0 To: agraf@suse.de, pbonzini@redhat.com X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c02::22a Cc: qemu-trivial@nongnu.org, qemu-ppc@nongnu.org, qemu-devel , kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH] target-ppc: kvm: Fix memory overflow issue about strncat() 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 strncat() will append additional '\0' to destination buffer, so need additional 1 byte for it, or may cause memory overflow, just like other area within QEMU have done. Signed-off-by: Chen Gang --- target-ppc/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 9c23c6b..66e7ce5 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -1794,8 +1794,8 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *propname) return -1; } - strncat(buf, "/", sizeof(buf) - strlen(buf)); - strncat(buf, propname, sizeof(buf) - strlen(buf)); + strncat(buf, "/", sizeof(buf) - strlen(buf) - 1); + strncat(buf, propname, sizeof(buf) - strlen(buf) - 1); f = fopen(buf, "rb"); if (!f) {