[Fedora-directory-commits] ldapserver/ldap/servers/slapd sasl_io.c, 1.6, 1.6.2.1

Noriko Hosoi (nhosoi) fedora-directory-commits at redhat.com
Wed Jan 9 19:37:06 UTC 2008


Author: nhosoi

Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv6670

Modified Files:
      Tag: Directory71RtmBranch
	sasl_io.c 
Log Message:
Resolves: 428159
Summary: SASL IO functions set/get: argument mismatch
Fix description: When setting the IO functions in sasl_io_setup, we could just
use the local memory to pass the IO functions.  And we don't need to worry about
releasing the memory.  Instead, we need to allocate the back up of the existing
IO functions (real_iofns in the code), which is set in sasl_io_setup and needs
to be released after setting it back in sasl_io_cleanup.



Index: sasl_io.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/sasl_io.c,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -r1.6 -r1.6.2.1
--- sasl_io.c	19 Apr 2005 22:07:37 -0000	1.6
+++ sasl_io.c	9 Jan 2008 19:37:04 -0000	1.6.2.1
@@ -100,15 +100,16 @@
 sasl_io_setup(Connection *c)
 {
     int ret = 0;
-    struct lber_x_ext_io_fns *func_pointers = NULL;
+    struct lber_x_ext_io_fns func_pointers = {0};
+    struct lber_x_ext_io_fns *real_iofns = (struct lber_x_ext_io_fns *) slapi_ch_malloc(LBER_X_EXTIO_FNS_SIZE);
     sasl_io_private *sp = (sasl_io_private*) slapi_ch_calloc(1, sizeof(sasl_io_private));
 
     LDAPDebug( LDAP_DEBUG_CONNS,
                 "sasl_io_setup for connection %d\n", c->c_connid, 0, 0 );
     /* Get the current functions and store them for later */
-    ber_sockbuf_get_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, &func_pointers);
-    sp->real_iofns = func_pointers;
-    func_pointers = NULL;
+    real_iofns->lbextiofn_size = LBER_X_EXTIO_FNS_SIZE;
+    ber_sockbuf_get_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, real_iofns );
+    sp->real_iofns = real_iofns; /* released in sasl_io_cleanup */
 
     /* Set up the private structure */
     sp->real_handle = (struct lextiof_socket_private*) c->c_prfd;
@@ -116,13 +117,12 @@
     /* Store the private structure in the connection */
     c->c_sasl_io_private = sp;
     /* Insert the sasl i/o functions into the ber layer */
-    func_pointers = (struct lber_x_ext_io_fns *) slapi_ch_malloc(LBER_X_EXTIO_FNS_SIZE);
-    func_pointers->lbextiofn_size = LBER_X_EXTIO_FNS_SIZE;
-    func_pointers->lbextiofn_read = sasl_read_function;
-    func_pointers->lbextiofn_write = sasl_write_function;
-    func_pointers->lbextiofn_writev = NULL;
-    func_pointers->lbextiofn_socket_arg = (struct lextiof_socket_private *) sp;
-    ber_sockbuf_set_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, func_pointers);
+    func_pointers.lbextiofn_size = LBER_X_EXTIO_FNS_SIZE;
+    func_pointers.lbextiofn_read = sasl_read_function;
+    func_pointers.lbextiofn_write = sasl_write_function;
+    func_pointers.lbextiofn_writev = NULL;
+    func_pointers.lbextiofn_socket_arg = (struct lextiof_socket_private *) sp;
+    ret = ber_sockbuf_set_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, &func_pointers);
     /* Setup the data buffers for the fast read path */
     sasl_io_init_buffers(sp);
     /* Reset the enable flag, so we don't process it again */
@@ -144,7 +144,10 @@
         slapi_ch_free((void**)&(sp->encrypted_buffer));
         slapi_ch_free((void**)&(sp->decrypted_buffer));
         /* Put the I/O functions back how they were */
-        ber_sockbuf_set_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, sp->real_iofns);
+        if (NULL != sp->real_iofns) {
+            ber_sockbuf_set_option( c->c_sb, LBER_SOCKBUF_OPT_EXT_IO_FNS, sp->real_iofns );
+            slapi_ch_free((void**)&(sp->real_iofns));
+        }
         slapi_ch_free((void**)&sp);
         c->c_sasl_io_private = NULL;
         c->c_enable_sasl_io = 0;




More information about the Fedora-directory-commits mailing list