]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fix uninitialised variable in two Windows event loops.
authorSimon Tatham <anakin@pobox.com>
Sat, 22 Nov 2014 10:18:16 +0000 (10:18 +0000)
committerSimon Tatham <anakin@pobox.com>
Sat, 22 Nov 2014 15:25:38 +0000 (15:25 +0000)
If (Msg)WaitForMultipleObjects returns WAIT_TIMEOUT, we expect 'next'
to have been initialised. This can occur without having called
run_timers(), if a toplevel callback was pending, so we can't expect
run_timers to have reliably initialised 'next'.

I'm not actually convinced this could have come up in either of the
affected programs (Windows PSFTP and Plink), due to the list of things
toplevel callbacks are currently used for, but it certainly wants
fixing anyway for the future.

Spotted by Coverity.

windows/winplink.c
windows/winsftp.c

index 1c4f3307cd50be20bb8ca06b93b8c8ae75daa3f9..43826622b4a0e64e4e6d2ef9a29867b253c8305d 100644 (file)
@@ -661,6 +661,7 @@ int main(int argc, char **argv)
 
         if (toplevel_callback_pending()) {
             ticks = 0;
+            next = now;
         } else if (run_timers(now, &next)) {
            then = now;
            now = GETTICKCOUNT();
@@ -670,6 +671,8 @@ int main(int argc, char **argv)
                ticks = next - now;
        } else {
            ticks = INFINITE;
+            /* no need to initialise next here because we can never
+             * get WAIT_TIMEOUT */
        }
 
        handles = handle_get_events(&nhandles);
index 25ac6c9482079b14e0b1218614f02aa77db2430b..f37ef2431236d056267dda4adcf51bfde8471b7a 100644 (file)
@@ -495,6 +495,7 @@ int do_eventsel_loop(HANDLE other_event)
 
     if (toplevel_callback_pending()) {
         ticks = 0;
+        next = now;
     } else if (run_timers(now, &next)) {
        then = now;
        now = GETTICKCOUNT();
@@ -504,6 +505,8 @@ int do_eventsel_loop(HANDLE other_event)
            ticks = next - now;
     } else {
        ticks = INFINITE;
+        /* no need to initialise next here because we can never get
+         * WAIT_TIMEOUT */
     }
 
     handles = handle_get_events(&nhandles);