From patchwork Fri Nov 3 14:54:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ZhiPeng Lu X-Patchwork-Id: 833918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3yT4k95z2qz9s8J for ; Sat, 4 Nov 2017 01:54:57 +1100 (AEDT) Received: from localhost ([::1]:37060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eAdN1-0002xW-Vy for incoming@patchwork.ozlabs.org; Fri, 03 Nov 2017 10:54:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eAdMk-0002xN-6l for qemu-devel@nongnu.org; Fri, 03 Nov 2017 10:54:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eAdMh-0000Az-5b for qemu-devel@nongnu.org; Fri, 03 Nov 2017 10:54:38 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:54406 helo=mxct.zte.com.cn) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eAdMg-00009f-Oz for qemu-devel@nongnu.org; Fri, 03 Nov 2017 10:54:35 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 0BADE314BA9196653998; Fri, 3 Nov 2017 22:54:29 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id vA3EsLUP024832; Fri, 3 Nov 2017 22:54:21 +0800 (GMT-8) (envelope-from lu.zhipeng@zte.com.cn) Received: from ceshi.localdomain ([10.74.120.130]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017110322542898-516038 ; Fri, 3 Nov 2017 22:54:28 +0800 From: ZhiPeng Lu To: mdroth@linux.vnet.ibm.com Date: Fri, 3 Nov 2017 22:54:20 +0800 Message-Id: <1509720860-10065-1-git-send-email-lu.zhipeng@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-11-03 22:54:29, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-11-03 22:54:06, Serialize complete at 2017-11-03 22:54:06 X-MAIL: mse01.zte.com.cn vA3EsLUP024832 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 202.103.147.172 Subject: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ZhiPeng Lu , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The data obtained by GetIfEntry is 32 bits, and it may overflow. Thus using GetIfEntry2 instead of GetIfEntry. Signed-off-by: ZhiPeng Lu --- qga/commands-win32.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/qga/commands-win32.c b/qga/commands-win32.c index 0322188..d096dc2 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1173,20 +1173,25 @@ static int guest_get_network_stats(const char *name, GuestNetworkInterfaceStat *stats) { DWORD if_index = 0; - MIB_IFROW a_mid_ifrow; - memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow)); + OSVERSIONINFO OSver; if_index = get_interface_index(name); - a_mid_ifrow.dwIndex = if_index; - if (NO_ERROR == GetIfEntry(&a_mid_ifrow)) { - stats->rx_bytes = a_mid_ifrow.dwInOctets; - stats->rx_packets = a_mid_ifrow.dwInUcastPkts; - stats->rx_errs = a_mid_ifrow.dwInErrors; - stats->rx_dropped = a_mid_ifrow.dwInDiscards; - stats->tx_bytes = a_mid_ifrow.dwOutOctets; - stats->tx_packets = a_mid_ifrow.dwOutUcastPkts; - stats->tx_errs = a_mid_ifrow.dwOutErrors; - stats->tx_dropped = a_mid_ifrow.dwOutDiscards; - return 0; + OSver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&OSver); + if (OSver.dwMajorVersion >= 6) { + MIB_IF_ROW2 a_mid_ifrow; + memset(&a_mid_ifrow, 0, sizeof(a_mid_ifrow)); + a_mid_ifrow.dwIndex = if_index; + if (NO_ERROR == GetIfEntry2(&a_mid_ifrow)) { + stats->rx_bytes = a_mid_ifrow.dwInOctets; + stats->rx_packets = a_mid_ifrow.dwInUcastPkts; + stats->rx_errs = a_mid_ifrow.dwInErrors; + stats->rx_dropped = a_mid_ifrow.dwInDiscards; + stats->tx_bytes = a_mid_ifrow.dwOutOctets; + stats->tx_packets = a_mid_ifrow.dwOutUcastPkts; + stats->tx_errs = a_mid_ifrow.dwOutErrors; + stats->tx_dropped = a_mid_ifrow.dwOutDiscards; + return 0; + } } return -1; }