Skip to content

Commit

Permalink
RSA_generate_key: declare all variables in PREINIT (#410)
Browse files Browse the repository at this point in the history
Closes #407.
  • Loading branch information
chrisnovakovic committed Dec 19, 2022
2 parents 32e32e7 + 7c346f5 commit bf3d907
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Revision history for Perl extension Net::SSLeay.
- LibreSSL on OpenBSD 6.9
- LibreSSL on OpenBSD 7.1
- Cygwin on x86_64
- Refactor variable declarations in RSA_generate_key to allow SSLeay.xs to
compile under -Werror=declaration-after-statement. Fixes GH-407. Thanks to
dharanlinux for the report.

1.93_01 2022-03-20
- LibreSSL 3.5.0 has removed access to internal data
Expand Down
13 changes: 8 additions & 5 deletions SSLeay.xs
Original file line number Diff line number Diff line change
Expand Up @@ -6328,16 +6328,21 @@ RSA_generate_key(bits,ee,perl_cb=&PL_sv_undef,perl_data=&PL_sv_undef)
SV* perl_data
PREINIT:
simple_cb_data_t* cb_data = NULL;
int rc;
RSA * ret;
BIGNUM *e;
#if (OPENSSL_VERSION_NUMBER >= 0x10100001L && !defined(LIBRESSL_VERSION_NUMBER)) || (LIBRESSL_VERSION_NUMBER >= 0x2070000fL)
BN_GENCB *new_cb;
#else
BN_GENCB new_cb;
#endif
CODE:
/* openssl 0.9.8 deprecated RSA_generate_key. */
/* This equivalent was contributed by Brian Fraser for Android, */
/* but was not portable to old OpenSSLs where RSA_generate_key_ex is not available. */
/* It should now be more versatile. */
/* as of openssl 1.1.0-pre1 it is not possible anymore to generate the BN_GENCB structure directly. */
/* instead BN_EGNCB_new() has to be used. */
int rc;
RSA * ret;
BIGNUM *e;
e = BN_new();
if(!e)
croak("Net::SSLeay: RSA_generate_key perl function could not create BN structure.\n");
Expand All @@ -6351,7 +6356,6 @@ RSA_generate_key(bits,ee,perl_cb=&PL_sv_undef,perl_data=&PL_sv_undef)
croak("Net::SSLeay: RSA_generate_key perl function could not create RSA structure.\n");
}
#if (OPENSSL_VERSION_NUMBER >= 0x10100001L && !defined(LIBRESSL_VERSION_NUMBER)) || (LIBRESSL_VERSION_NUMBER >= 0x2070000fL)
BN_GENCB *new_cb;
new_cb = BN_GENCB_new();
if(!new_cb) {
simple_cb_data_free(cb_data);
Expand All @@ -6363,7 +6367,6 @@ RSA_generate_key(bits,ee,perl_cb=&PL_sv_undef,perl_data=&PL_sv_undef)
rc = RSA_generate_key_ex(ret, bits, e, new_cb);
BN_GENCB_free(new_cb);
#else
BN_GENCB new_cb;
BN_GENCB_set_old(&new_cb, ssleay_RSA_generate_key_cb_invoke, cb_data);
rc = RSA_generate_key_ex(ret, bits, e, &new_cb);
#endif
Expand Down

0 comments on commit bf3d907

Please sign in to comment.