https://bugs.openldap.org/show_bug.cgi?id=9181
--- Comment #2 from Howard Chu hyc@symas.com --- (In reply to Ondřej Kuzník from comment #1)
On Tue, Mar 10, 2020 at 02:47:09PM +0000, edwin.mons@isode.com wrote:
The global options have a mutex, ldo_mutex, that is left NUL-initialised. This is no problem on must platforms where a mutex is a structure, and all NUL values is a valid mutex, but on Windows, the mutex is a handle. This handle is invalid if it's 0, which causes WaitForSingleObject to return an error.
ldap_set_option tries to obtain a lock on the global options. On anything but Windows, this protects data corruption in multi-threaded use, but on Windows, it didn't: there wasn't a mutex to lock, and the result of LDAP_MUTEX_LOCK is never checked.
I fixed my local build of OpenLDAP using the attached patch, which satisfied both Application Verifier, and stopped our product from crashing in certain tests that call ldap_set_options from multiple worker threads (in our case, the OpenSSL context was sometimes corrupted.)
Hi Edwin, thanks for the patch.
Looking at it in the context of ITS#7996, it seems the race outlined in that ticket is not completely fixed on Windows? Do you know a way to achieve a desired behaviour there?
I've had to solve this problem recently in another project. I'll take care of this.