dlls/icmp/icmp_main.c -- attempt at fixing regression in r1.30 (RESEND)

Gerald Pfeifer gerald at pfeifer.com
Tue Dec 4 18:34:23 CST 2007


Since Alexandre has asked me to take care of overflow in some other
context, I figured I could ping this underflow patch in return. ;-)

Gerald

---------- Forwarded message ----------
From: Gerald Pfeifer <gerald at pfeifer.com>
To:  <wine-patches at winehq.org>, Damjan Jovanovic <damjan.jov at gmail.com>
Date: Thu, 22 Nov 2007 22:32:08 +0100 (CET)
Subject: dlls/icmp/icmp_main.c -- attempt at fixing regression in r1.30

I believe revision 1.30 of dlls/icmp/icmp_main.c

  date: 2006-11-06 11:51:07 +0000;  author: julliard;  state: Exp;  lines: +10 -15;
  Damjan Jovanovic <damjan.jov at gmail.com>
  icmp: Changed select to poll.

introduced a bug by replacing

  int t = Timeout - (recv_time - send_time);
  if (t < 0) t = 0;
  timeout.tv_sec = t / 1000;
  timeout.tv_usec = (t % 1000) * 1000;

with

  Timeout -= (recv_time - send_time);
  if (Timeout < 0) Timeout = 0;

The problem here is that Timeout is of type DWORD and thus "underflow"
will never be detected and the if-condition will never actually trigger.

The patch below is a simple attempt to address this.  Thoughts?

Gerald

Index: dlls/icmp/icmp_main.c
===================================================================
RCS file: /home/wine/wine/dlls/icmp/icmp_main.c,v
retrieving revision 1.30
diff -u -3 -p -r1.30 icmp_main.c
--- dlls/icmp/icmp_main.c	6 Nov 2006 11:51:07 -0000	1.30
+++ dlls/icmp/icmp_main.c	22 Nov 2007 21:28:59 -0000
@@ -433,8 +433,9 @@ DWORD WINAPI IcmpSendEcho(
              * Decrease the timeout so that we don't enter an endless loop even
              * if we get flooded with ICMP packets that are not for us.
              */
-            Timeout -= (recv_time - send_time);
-            if (Timeout < 0) Timeout = 0;
+            DWORD t = (recv_time - send_time);
+            if (Timeout > t) Timeout -= t;
+            else             Timeout = 0;
             continue;
         } else {
             /* This is a reply to our packet */



More information about the wine-patches mailing list