Skip to content

Commit

Permalink
Use i2d_X509 in a way that don't change ErlNifBinary fields
Browse files Browse the repository at this point in the history
i2d_x509 is a macro and it change pointer value that is passed to it,
previous version was passing reference to ErlNifBinary data field which
was changed by it - and that causes problem on R27, so let switch to
standalone pointer that shouldn't cause troubles.
  • Loading branch information
prefiks committed Feb 26, 2024
1 parent e355284 commit 528d975
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions c_src/fast_tls.c
Expand Up @@ -1168,7 +1168,6 @@ static ERL_NIF_TERM get_peer_certificate_nif(ErlNifEnv *env, int argc,
X509 *cert = NULL;
state_t *state = NULL;
int rlen;
ErlNifBinary output;

if (argc != 1)
return enif_make_badarg(env);
Expand All @@ -1193,14 +1192,16 @@ static ERL_NIF_TERM get_peer_certificate_nif(ErlNifEnv *env, int argc,
}
rlen = i2d_X509(cert, NULL);
if (rlen >= 0) {
if (!enif_alloc_binary(rlen, &output)) {
ERL_NIF_TERM bin;
unsigned char *buf = enif_make_new_binary(env, rlen, &bin);
if (!buf) {
enif_mutex_unlock(state->mtx);
return ERR_T(enif_make_atom(env, "enomem"));
}
i2d_X509(cert, &output.data);
i2d_X509(cert, &buf);
X509_free(cert);
enif_mutex_unlock(state->mtx);
return OK_T(enif_make_binary(env, &output));
return OK_T(bin);
} else {
X509_free(cert);
enif_mutex_unlock(state->mtx);
Expand Down

0 comments on commit 528d975

Please sign in to comment.