]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/tls_m.c
Plug one-time leaks
[openldap] / libraries / libldap / tls_m.c
index 4bd9e63cb5a8dea03e2464ecc89d5c107debe060..c1d0c2eefe4384aa03cf437ecdead3e3ed235cf9 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2008-2013 The OpenLDAP Foundation.
+ * Copyright 2008-2014 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -2066,8 +2066,10 @@ tlsm_ctx_free ( tls_ctx *ctx )
                                   errcode, PR_ErrorToString( errcode, PR_LANGUAGE_I_DEFAULT ), 0 );
                }
        }
-       PL_strfree( c->tc_pin_file );
-       c->tc_pin_file = NULL;
+       if ( c->tc_pin_file ) {
+               PL_strfree( c->tc_pin_file );
+               c->tc_pin_file = NULL;
+       }
        tlsm_free_pem_objs( c );
 #ifdef HAVE_NSS_INITCONTEXT
        if ( c->tc_initctx ) {
@@ -2317,7 +2319,8 @@ tlsm_deferred_ctx_init( void *arg )
                                return rc;
                        }
                } else {
-                       PL_strfree( ctx->tc_pin_file );
+                       if ( ctx->tc_pin_file )
+                               PL_strfree( ctx->tc_pin_file );
                        ctx->tc_pin_file = PL_strdup( lt->lt_keyfile );
                }
        }
@@ -2891,6 +2894,22 @@ tlsm_session_cipher( tls_session *sess )
        return "unknown";
 }
 
+static int
+tlsm_session_peercert( tls_session *sess, struct berval *der )
+{
+       tlsm_session *s = (tlsm_session *)sess;
+       CERTCertificate *cert;
+       cert = SSL_PeerCertificate( s );
+       if (!cert)
+               return -1;
+       der->bv_len = cert->derCert.len;
+       der->bv_val = LDAP_MALLOC( der->bv_len );
+       if (!der->bv_val)
+               return -1;
+       memcpy( der->bv_val, cert->derCert.data, der->bv_len );
+       return 0;
+}
+
 /*
  * TLS support for LBER Sockbufs
  */
@@ -3322,6 +3341,7 @@ tls_impl ldap_int_tls_impl = {
        tlsm_session_unique,
        tlsm_session_version,
        tlsm_session_cipher,
+       tlsm_session_peercert,
 
        &tlsm_sbio,