[PATCH 2/2] inetmib1: Fix the IPv4 address network order for comparisons.

Francois Gouget fgouget at codeweavers.com
Mon Feb 14 20:35:58 CST 2022


compareUdpRow() was already performing the byte-swaps but
compareIpAddrRow() and compareIpForwardRow() need them too.

Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
The byte order was fixed in compareUdpRow() for bug 52224:
https://bugs.winehq.org/show_bug.cgi?id=52224

There is no specific test for this but adding traces showed that
the other two comparison functions were also operating on the wrong
byte order.
---
 dlls/inetmib1/main.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/inetmib1/main.c b/dlls/inetmib1/main.c
index d19648ff792..d5bcc45a1e9 100644
--- a/dlls/inetmib1/main.c
+++ b/dlls/inetmib1/main.c
@@ -773,9 +773,11 @@ static void oidToIpAddrRow(AsnObjectIdentifier *oid, void *dst)
 static int __cdecl compareIpAddrRow(const void *a, const void *b)
 {
     const MIB_IPADDRROW *rowA = a, *rowB = b;
+    ULONG addrA = ntohl( rowA->dwAddr );
+    ULONG addrB = ntohl( rowB->dwAddr );
 
-    return rowA->dwAddr < rowB->dwAddr ? -1 : /* avoids overflows */
-           rowA->dwAddr > rowB->dwAddr ? 1 :
+    return addrA < addrB ? -1 : /* avoids overflows */
+           addrA > addrB ? 1 :
            0;
 }
 
@@ -868,9 +870,11 @@ static void oidToIpForwardRow(AsnObjectIdentifier *oid, void *dst)
 static int __cdecl compareIpForwardRow(const void *a, const void *b)
 {
     const MIB_IPFORWARDROW *rowA = a, *rowB = b;
+    ULONG addrA = ntohl( rowA->dwForwardDest );
+    ULONG addrB = ntohl( rowB->dwForwardDest );
 
-    return rowA->dwForwardDest < rowB->dwForwardDest ? -1 : /* avoids overflows */
-           rowA->dwForwardDest > rowB->dwForwardDest ? 1 :
+    return addrA < addrB ? -1 : /* avoids overflows */
+           addrA > addrB ? 1 :
            0;
 }
 
-- 
2.30.2



More information about the wine-devel mailing list