Skip to content

Commit

Permalink
Initialize driver data with memset.
Browse files Browse the repository at this point in the history
Driver data structure was initialized in start() one field at
a time. This is error prone (in fact, bio_read and bio_write
were not initialized there). Use memset to initialize the whole
structure.
Additionally, set connection and context structures to NULL in
error path of init_library().
  • Loading branch information
rraptorr authored and badlop committed Sep 20, 2011
1 parent 452442b commit 7bbfd28
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions c_src/exmpp_tls_openssl.c
Expand Up @@ -123,19 +123,7 @@ exmpp_tls_openssl_start(ErlDrvPort port, char *command)
if (edd == NULL)
return (NULL);

edd->mode = TLS_MODE_UNKNOWN;
edd->certificate = edd->private_key = NULL;
edd->verify_peer = 0;
edd->expected_id = NULL;
edd->trusted_certs = NULL;
edd->peer_cert_required = 0;
edd->accept_expired_cert = 0;
edd->accept_revoked_cert = 0;
edd->accept_non_trusted_cert = 0;
edd->accept_corrupted_cert = 0;

edd->ctx = NULL;
edd->ssl = NULL;
memset(edd, 0, sizeof(*edd));

return (ErlDrvData)edd;
}
Expand Down Expand Up @@ -721,10 +709,14 @@ init_library(struct exmpp_tls_openssl_data *edd,
return (0);

err:
if (edd->ssl != NULL)
if (edd->ssl != NULL) {
SSL_free(edd->ssl);
if (edd->ctx != NULL)
edd->ssl = NULL;
}
if (edd->ctx != NULL) {
SSL_CTX_free(edd->ctx);
edd->ctx = NULL;
}

return (-1);
}
Expand Down

0 comments on commit 7bbfd28

Please sign in to comment.