qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v2] qga: replace GetIfEntry


From: ZhiPeng Lu
Subject: [Qemu-devel] [PATCH v2] qga: replace GetIfEntry
Date: Fri, 3 Nov 2017 22:54:20 +0800

The data obtained by GetIfEntry is 32 bits, and it may overflow. Thus using 
GetIfEntry2 instead of GetIfEntry.

Signed-off-by: ZhiPeng Lu <address@hidden>
---
 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;
 }
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]