rand_win.c: handel GetTickCount wrap-around [from HEAD].
authorAndy Polyakov <appro@openssl.org>
Tue, 19 Jan 2010 21:44:07 +0000 (21:44 +0000)
committerAndy Polyakov <appro@openssl.org>
Tue, 19 Jan 2010 21:44:07 +0000 (21:44 +0000)
crypto/rand/rand_win.c

index efe0f89..9bad067 100644 (file)
@@ -463,7 +463,7 @@ int RAND_poll(void)
                PROCESSENTRY32 p;
                THREADENTRY32 t;
                MODULEENTRY32 m;
                PROCESSENTRY32 p;
                THREADENTRY32 t;
                MODULEENTRY32 m;
-               DWORD stoptime = 0;
+               DWORD starttime = 0;
 
                snap = (CREATETOOLHELP32SNAPSHOT)
                        GetProcAddress(kernel, "CreateToolhelp32Snapshot");
 
                snap = (CREATETOOLHELP32SNAPSHOT)
                        GetProcAddress(kernel, "CreateToolhelp32Snapshot");
@@ -496,7 +496,7 @@ int RAND_poll(void)
                          */
                        ZeroMemory(&hlist, sizeof(HEAPLIST32));
                        hlist.dwSize = sizeof(HEAPLIST32);              
                          */
                        ZeroMemory(&hlist, sizeof(HEAPLIST32));
                        hlist.dwSize = sizeof(HEAPLIST32);              
-                       if (good) stoptime = GetTickCount() + MAXDELAY;
+                       if (good) starttime = GetTickCount();
 #ifdef _MSC_VER
                        if (heaplist_first(handle, &hlist))
                                {
 #ifdef _MSC_VER
                        if (heaplist_first(handle, &hlist))
                                {
@@ -536,7 +536,7 @@ int RAND_poll(void)
                                                        ex_cnt_limit--;
                                                }
                                        } while (heaplist_next(handle, &hlist) 
                                                        ex_cnt_limit--;
                                                }
                                        } while (heaplist_next(handle, &hlist) 
-                                               && GetTickCount() < stoptime 
+                                               && (!good || (GetTickCount()-starttime)<MAXDELAY)
                                                && ex_cnt_limit > 0);
                                }
 
                                                && ex_cnt_limit > 0);
                                }
 
@@ -559,7 +559,7 @@ int RAND_poll(void)
                                                        && --entrycnt > 0);
                                                }
                                        } while (heaplist_next(handle, &hlist) 
                                                        && --entrycnt > 0);
                                                }
                                        } while (heaplist_next(handle, &hlist) 
-                                               && GetTickCount() < stoptime);
+                                               && (!good || (GetTickCount()-starttime)<MAXDELAY));
                                }
 #endif
 
                                }
 #endif
 
@@ -570,11 +570,11 @@ int RAND_poll(void)
                          */
                        p.dwSize = sizeof(PROCESSENTRY32);
                
                          */
                        p.dwSize = sizeof(PROCESSENTRY32);
                
-                       if (good) stoptime = GetTickCount() + MAXDELAY;
+                       if (good) starttime = GetTickCount();
                        if (process_first(handle, &p))
                                do
                                        RAND_add(&p, p.dwSize, 9);
                        if (process_first(handle, &p))
                                do
                                        RAND_add(&p, p.dwSize, 9);
-                               while (process_next(handle, &p) && GetTickCount() < stoptime);
+                               while (process_next(handle, &p) && (!good || (GetTickCount()-starttime)<MAXDELAY));
 
                        /* thread walking */
                         /* THREADENTRY32 contains 6 fields that will change
 
                        /* thread walking */
                         /* THREADENTRY32 contains 6 fields that will change
@@ -582,11 +582,11 @@ int RAND_poll(void)
                          * 1 byte of entropy.
                          */
                        t.dwSize = sizeof(THREADENTRY32);
                          * 1 byte of entropy.
                          */
                        t.dwSize = sizeof(THREADENTRY32);
-                       if (good) stoptime = GetTickCount() + MAXDELAY;
+                       if (good) starttime = GetTickCount();
                        if (thread_first(handle, &t))
                                do
                                        RAND_add(&t, t.dwSize, 6);
                        if (thread_first(handle, &t))
                                do
                                        RAND_add(&t, t.dwSize, 6);
-                               while (thread_next(handle, &t) && GetTickCount() < stoptime);
+                               while (thread_next(handle, &t) && (!good || (GetTickCount()-starttime)<MAXDELAY));
 
                        /* module walking */
                         /* MODULEENTRY32 contains 9 fields that will change
 
                        /* module walking */
                         /* MODULEENTRY32 contains 9 fields that will change
@@ -594,12 +594,12 @@ int RAND_poll(void)
                          * 1 byte of entropy.
                          */
                        m.dwSize = sizeof(MODULEENTRY32);
                          * 1 byte of entropy.
                          */
                        m.dwSize = sizeof(MODULEENTRY32);
-                       if (good) stoptime = GetTickCount() + MAXDELAY;
+                       if (good) starttime = GetTickCount();
                        if (module_first(handle, &m))
                                do
                                        RAND_add(&m, m.dwSize, 9);
                                while (module_next(handle, &m)
                        if (module_first(handle, &m))
                                do
                                        RAND_add(&m, m.dwSize, 9);
                                while (module_next(handle, &m)
-                                               && (GetTickCount() < stoptime));
+                                               && (!good || (GetTickCount()-starttime)<MAXDELAY));
                        if (close_snap)
                                close_snap(handle);
                        else
                        if (close_snap)
                                close_snap(handle);
                        else