[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#5606) Attempt to close unopened sockets when daemon doesn't run as a daemon



Full_Name: Ben Schmidt
Version: 2.4.10
OS: MinGW32, Mac OS X
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (124.168.9.190)


I have recently cross-compiled OpenLDAP for MinGW32 on Mac OS X. I found two
bugs in the source code relating to shutdown/freeing structures.

This is the first.

Because slapd_daemon_destroy can be called without slapd_deamon_init being
called (e.g. if testing configuration, or giving -VV as the documentation
suggests does something, though I'm not sure what), an attempt can be made to
close sockets not opened. I suggest the following fix:

diff -ru --exclude=Makefile openldap-2.4.10/servers/slapd/daemon.c
openldap/servers/slapd/daemon.c
--- openldap-2.4.10/servers/slapd/daemon.c	2008-05-28 06:12:44.000000000 +1000
+++ openldap/servers/slapd/daemon.c	2008-06-28 21:54:38.000000000 +1000
@@ -79,7 +79,7 @@
 #define SLAPD_LISTEN_BACKLOG 1024
 #endif /* ! SLAPD_LISTEN_BACKLOG */
 
-static ber_socket_t wake_sds[2];
+static ber_socket_t wake_sds[2] = {INVALID_SOCKET, INVALID_SOCKET};
 static int emfile;
 
 static volatile int waking;
@@ -1641,8 +1643,10 @@
 slapd_daemon_destroy( void )
 {
 	connections_destroy();
-	tcp_close( SLAP_FD2SOCK(wake_sds[1]) );
-	tcp_close( SLAP_FD2SOCK(wake_sds[0]) );
+	if ( wake_sds[1] != INVALID_SOCKET )
+		tcp_close( SLAP_FD2SOCK(wake_sds[1]) );
+	if ( wake_sds[0] != INVALID_SOCKET )
+		tcp_close( SLAP_FD2SOCK(wake_sds[0]) );
 	sockdestroy();
 
 #ifdef HAVE_SLP

I couldn't find this mentioned in your tracker already.