In message <[EMAIL PROTECTED]> on Thu, 07 Aug 2003 08:54:19 +0100, Martin Kochanski 
<[EMAIL PROTECTED]> said:

openssl> 1. Minor bug:
openssl> 
openssl> Line 443 of rand_win.c reads (reformatted)
openssl> 
openssl>    && (handle = snap(TH32CS_SNAPALL,0))!= NULL
openssl> 
openssl> ["snap" is a variable that holds the address of
openssl> CreateToolhelp32Snapshot].
openssl> 
openssl> Microsoft's documentation states that -1
openssl> (INVALID_HANDLE_VALUE), not NULL, is returned on failure.
openssl> 
openssl> 2. Memory leak under Windows CE:
openssl> 
openssl> RAND_poll() calls CloseHandle(handle) to close the handle
openssl> opened by CreateToolhelp32Snapshot. This is what we should be
openssl> doing under Windows, but under Windows CE, Microsoft's
openssl> documentation states: "To close a snapshot call the
openssl> CloseToolhelp32Snapshot function. Do not call the CloseHandle
openssl> function to close the snapshot call. Calling CloseHandle to
openssl> close the snapshot call generates a memory leak."
openssl> 
openssl> I'm not sure whether OpenSSL counts Windows CE as a supported
openssl> platform, but if it does, this needs to be accounted for.

For those two errors, I propose the following change:

Index: crypto/rand/rand_win.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/rand/rand_win.c,v
retrieving revision 1.32
diff -u -r1.32 rand_win.c
--- crypto/rand/rand_win.c      3 Dec 2002 14:20:31 -0000       1.32
+++ crypto/rand/rand_win.c      7 Aug 2003 09:42:55 -0000
@@ -162,6 +162,7 @@
 typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);
 
 typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
+typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
 typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
 typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
 typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
@@ -431,7 +432,7 @@
         * This seeding method was proposed in Peter Gutmann, Software
         * Generation of Practically Strong Random Numbers,
         * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
-     * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
+        * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
         * (The assignment of entropy estimates below is arbitrary, but based
         * on Peter's analysis the full poll appears to be safe. Additional
         * interactive seeding is encouraged.)
@@ -440,6 +441,7 @@
        if (kernel)
                {
                CREATETOOLHELP32SNAPSHOT snap;
+               CLOSETOOLHELP32SNAPSHOT snap_close;
                HANDLE handle;
 
                HEAP32FIRST heap_first;
@@ -457,6 +459,8 @@
 
                snap = (CREATETOOLHELP32SNAPSHOT)
                        GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot"));
+               snap_close = (CLOSETOOLHELP32SNAPSHOT)
+                       GetProcAddress(kernel, TEXT("CloseToolhelp32Snapshot"));
                heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First"));
                heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next"));
                heaplist_first = (HEAP32LIST) GetProcAddress(kernel, 
TEXT("Heap32ListFirst"));
@@ -472,7 +476,7 @@
                        heaplist_next && process_first && process_next &&
                        thread_first && thread_next && module_first &&
                        module_next && (handle = snap(TH32CS_SNAPALL,0))
-                       != NULL)
+                       != INVALID_HANDLE_VALUE)
                        {
                        /* heap list and heap walking */
                         /* HEAPLIST32 contains 3 fields that will change with
@@ -534,8 +538,10 @@
                                do
                                        RAND_add(&m, m.dwSize, 9);
                                while (module_next(handle, &m));
-
-                       CloseHandle(handle);
+                       if (close_snap)
+                               close_snap(handle);
+                       else
+                               CloseHandle(handle);
                        }
 
                FreeLibrary(kernel);

-- 
Richard Levitte   \ Tunnlandsvägen 3  \ [EMAIL PROTECTED]
[EMAIL PROTECTED]  \ S-168 36  BROMMA  \ T: +46-8-26 52 47
                    \      SWEDEN       \ or +46-708-26 53 44
Procurator Odiosus Ex Infernis                -- [EMAIL PROTECTED]
Member of the OpenSSL development team: http://www.openssl.org/

Unsolicited commercial email is subject to an archival fee of $400.
See <http://www.stacken.kth.se/~levitte/mail/> for more info.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to