Don't link shlibloadtest against libcrypto
The whole point of shlibloadtest is to test dynamically loading and unloading the library. If we link shlibloadtest against libcrypto then that might mask potential issues. Reviewed-by: Tim Hudson <tjh@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7647)
This commit is contained in:
parent
8f6a5c56c1
commit
d0f2f202c5
2 changed files with 90 additions and 50 deletions
|
@ -392,7 +392,6 @@ INCLUDE_MAIN___test_libtestutil_OLB = /INCLUDE=main
|
||||||
PROGRAMS_NO_INST=shlibloadtest
|
PROGRAMS_NO_INST=shlibloadtest
|
||||||
SOURCE[shlibloadtest]=shlibloadtest.c
|
SOURCE[shlibloadtest]=shlibloadtest.c
|
||||||
INCLUDE[shlibloadtest]=../include ../crypto/include
|
INCLUDE[shlibloadtest]=../include ../crypto/include
|
||||||
DEPEND[shlibloadtest]=libtestutil.a
|
|
||||||
ENDIF
|
ENDIF
|
||||||
|
|
||||||
IF[{- $disabled{shared} -}]
|
IF[{- $disabled{shared} -}]
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
#include <openssl/ossl_typ.h>
|
#include <openssl/ossl_typ.h>
|
||||||
#include "internal/dso_conf.h"
|
#include "internal/dso_conf.h"
|
||||||
#include "testutil.h"
|
|
||||||
|
|
||||||
typedef void DSO;
|
typedef void DSO;
|
||||||
|
|
||||||
|
@ -122,57 +121,70 @@ static int test_lib(void)
|
||||||
switch (test_type) {
|
switch (test_type) {
|
||||||
case JUST_CRYPTO:
|
case JUST_CRYPTO:
|
||||||
case DSO_REFTEST:
|
case DSO_REFTEST:
|
||||||
if (!TEST_true(shlib_load(path_crypto, &cryptolib)))
|
|
||||||
goto end;
|
|
||||||
break;
|
|
||||||
case CRYPTO_FIRST:
|
case CRYPTO_FIRST:
|
||||||
if (!TEST_true(shlib_load(path_crypto, &cryptolib))
|
if (!shlib_load(path_crypto, &cryptolib)) {
|
||||||
|| !TEST_true(shlib_load(path_ssl, &ssllib)))
|
fprintf(stderr, "Failed to load libcrypto\n");
|
||||||
goto end;
|
goto end;
|
||||||
break;
|
}
|
||||||
|
if (test_type != CRYPTO_FIRST)
|
||||||
|
break;
|
||||||
|
/* Fall through */
|
||||||
|
|
||||||
case SSL_FIRST:
|
case SSL_FIRST:
|
||||||
if (!TEST_true(shlib_load(path_ssl, &ssllib))
|
if (!shlib_load(path_ssl, &ssllib)) {
|
||||||
|| !TEST_true(shlib_load(path_crypto, &cryptolib)))
|
fprintf(stderr, "Failed to load libssl\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
if (test_type != SSL_FIRST)
|
||||||
|
break;
|
||||||
|
if (!shlib_load(path_crypto, &cryptolib)) {
|
||||||
|
fprintf(stderr, "Failed to load libcrypto\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_type != JUST_CRYPTO && test_type != DSO_REFTEST) {
|
if (test_type != JUST_CRYPTO && test_type != DSO_REFTEST) {
|
||||||
if (!TEST_true(shlib_sym(ssllib, "TLS_method", &symbols[0].sym))
|
if (!shlib_sym(ssllib, "TLS_method", &symbols[0].sym)
|
||||||
|| !TEST_true(shlib_sym(ssllib, "SSL_CTX_new", &symbols[1].sym))
|
|| !shlib_sym(ssllib, "SSL_CTX_new", &symbols[1].sym)
|
||||||
|| !TEST_true(shlib_sym(ssllib, "SSL_CTX_free", &symbols[2].sym)))
|
|| !shlib_sym(ssllib, "SSL_CTX_free", &symbols[2].sym)) {
|
||||||
|
fprintf(stderr, "Failed to load libssl symbols\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
myTLS_method = (TLS_method_t)symbols[0].func;
|
myTLS_method = (TLS_method_t)symbols[0].func;
|
||||||
mySSL_CTX_new = (SSL_CTX_new_t)symbols[1].func;
|
mySSL_CTX_new = (SSL_CTX_new_t)symbols[1].func;
|
||||||
mySSL_CTX_free = (SSL_CTX_free_t)symbols[2].func;
|
mySSL_CTX_free = (SSL_CTX_free_t)symbols[2].func;
|
||||||
if (!TEST_ptr(ctx = mySSL_CTX_new(myTLS_method())))
|
ctx = mySSL_CTX_new(myTLS_method());
|
||||||
|
if (ctx == NULL) {
|
||||||
|
fprintf(stderr, "Failed to create SSL_CTX\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
mySSL_CTX_free(ctx);
|
mySSL_CTX_free(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TEST_true(shlib_sym(cryptolib, "ERR_get_error", &symbols[0].sym))
|
if (!shlib_sym(cryptolib, "ERR_get_error", &symbols[0].sym)
|
||||||
|| !TEST_true(shlib_sym(cryptolib, "OPENSSL_version_major",
|
|| !shlib_sym(cryptolib, "OPENSSL_version_major", &symbols[1].sym)
|
||||||
&symbols[1].sym))
|
|| !shlib_sym(cryptolib, "OPENSSL_version_minor", &symbols[2].sym)
|
||||||
|| !TEST_true(shlib_sym(cryptolib, "OPENSSL_version_minor",
|
|| !shlib_sym(cryptolib, "OPENSSL_version_patch", &symbols[3].sym)) {
|
||||||
&symbols[2].sym))
|
fprintf(stderr, "Failed to load libcrypto symbols\n");
|
||||||
|| !TEST_true(shlib_sym(cryptolib, "OPENSSL_version_patch",
|
|
||||||
&symbols[3].sym)))
|
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
myERR_get_error = (ERR_get_error_t)symbols[0].func;
|
myERR_get_error = (ERR_get_error_t)symbols[0].func;
|
||||||
if (!TEST_int_eq(myERR_get_error(), 0))
|
if (myERR_get_error() != 0) {
|
||||||
|
fprintf(stderr, "Unexpected ERR_get_error() response\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
/* Make sure the libraries are a compatible version */
|
/* Library and header version should be identical in this test */
|
||||||
myOPENSSL_version_major = (OPENSSL_version_major_t)symbols[1].func;
|
myOPENSSL_version_major = (OPENSSL_version_major_t)symbols[1].func;
|
||||||
myOPENSSL_version_minor = (OPENSSL_version_minor_t)symbols[2].func;
|
myOPENSSL_version_minor = (OPENSSL_version_minor_t)symbols[2].func;
|
||||||
myOPENSSL_version_patch = (OPENSSL_version_patch_t)symbols[3].func;
|
myOPENSSL_version_patch = (OPENSSL_version_patch_t)symbols[3].func;
|
||||||
if (!TEST_int_eq(myOPENSSL_version_major(), OPENSSL_VERSION_MAJOR))
|
if (myOPENSSL_version_major() != OPENSSL_VERSION_MAJOR
|
||||||
goto end;
|
|| myOPENSSL_version_minor() != OPENSSL_VERSION_MINOR
|
||||||
if (!TEST_int_ge(myOPENSSL_version_minor(), OPENSSL_VERSION_MINOR))
|
|| myOPENSSL_version_patch() != OPENSSL_VERSION_PATCH) {
|
||||||
goto end;
|
fprintf(stderr, "Invalid library version number\n");
|
||||||
if (myOPENSSL_version_minor() == OPENSSL_VERSION_MINOR
|
|
||||||
&& !TEST_int_ge(myOPENSSL_version_patch(), OPENSSL_VERSION_PATCH))
|
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
if (test_type == DSO_REFTEST) {
|
if (test_type == DSO_REFTEST) {
|
||||||
# ifdef DSO_DLFCN
|
# ifdef DSO_DLFCN
|
||||||
|
@ -187,10 +199,11 @@ static int test_lib(void)
|
||||||
* will always return an error, because DSO_pathbyaddr() is not
|
* will always return an error, because DSO_pathbyaddr() is not
|
||||||
* implemented there.
|
* implemented there.
|
||||||
*/
|
*/
|
||||||
if (!TEST_true(shlib_sym(cryptolib, "DSO_dsobyaddr", &symbols[0].sym))
|
if (!shlib_sym(cryptolib, "DSO_dsobyaddr", &symbols[0].sym)
|
||||||
|| !TEST_true(shlib_sym(cryptolib, "DSO_free",
|
|| !shlib_sym(cryptolib, "DSO_free", &symbols[1].sym)) {
|
||||||
&symbols[1].sym)))
|
fprintf(stderr, "Unable to load DSO symbols\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
myDSO_dsobyaddr = (DSO_dsobyaddr_t)symbols[0].func;
|
myDSO_dsobyaddr = (DSO_dsobyaddr_t)symbols[0].func;
|
||||||
myDSO_free = (DSO_free_t)symbols[1].func;
|
myDSO_free = (DSO_free_t)symbols[1].func;
|
||||||
|
@ -198,8 +211,11 @@ static int test_lib(void)
|
||||||
{
|
{
|
||||||
DSO *hndl;
|
DSO *hndl;
|
||||||
/* use known symbol from crypto module */
|
/* use known symbol from crypto module */
|
||||||
if (!TEST_ptr(hndl = myDSO_dsobyaddr((void (*)(void))ERR_get_error, 0)))
|
hndl = myDSO_dsobyaddr((void (*)(void))myERR_get_error, 0);
|
||||||
|
if (hndl == NULL) {
|
||||||
|
fprintf(stderr, "DSO_dsobyaddr() failed\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
myDSO_free(hndl);
|
myDSO_free(hndl);
|
||||||
}
|
}
|
||||||
# endif /* DSO_DLFCN */
|
# endif /* DSO_DLFCN */
|
||||||
|
@ -208,18 +224,27 @@ static int test_lib(void)
|
||||||
switch (test_type) {
|
switch (test_type) {
|
||||||
case JUST_CRYPTO:
|
case JUST_CRYPTO:
|
||||||
case DSO_REFTEST:
|
case DSO_REFTEST:
|
||||||
if (!TEST_true(shlib_close(cryptolib)))
|
|
||||||
goto end;
|
|
||||||
break;
|
|
||||||
case CRYPTO_FIRST:
|
case CRYPTO_FIRST:
|
||||||
if (!TEST_true(shlib_close(cryptolib))
|
if (!shlib_close(cryptolib)) {
|
||||||
|| !TEST_true(shlib_close(ssllib)))
|
fprintf(stderr, "Failed to close libcrypto\n");
|
||||||
goto end;
|
goto end;
|
||||||
break;
|
}
|
||||||
|
if (test_type != CRYPTO_FIRST)
|
||||||
|
break;
|
||||||
|
/* Fall through */
|
||||||
|
|
||||||
case SSL_FIRST:
|
case SSL_FIRST:
|
||||||
if (!TEST_true(shlib_close(ssllib))
|
if (test_type == CRYPTO_FIRST && !shlib_close(ssllib)) {
|
||||||
|| !TEST_true(shlib_close(cryptolib)))
|
fprintf(stderr, "Failed to close libssl\n");
|
||||||
goto end;
|
goto end;
|
||||||
|
}
|
||||||
|
if (test_type != SSL_FIRST)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!shlib_close(cryptolib)) {
|
||||||
|
fprintf(stderr, "Failed to close libcrypto\n");
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,9 +255,21 @@ end:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int setup_tests(void)
|
/*
|
||||||
|
* shlibloadtest should not use the normal test framework because we don't want
|
||||||
|
* it to link against libcrypto (which the framework uses). The point of the
|
||||||
|
* test is to check dynamic loading and unloading of libcrypto/libssl.
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *p = test_get_argument(0);
|
const char *p;
|
||||||
|
|
||||||
|
if (argc != 4) {
|
||||||
|
fprintf(stderr, "Incorrect number of arguments");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = argv[1];
|
||||||
|
|
||||||
if (strcmp(p, "-crypto_first") == 0) {
|
if (strcmp(p, "-crypto_first") == 0) {
|
||||||
test_type = CRYPTO_FIRST;
|
test_type = CRYPTO_FIRST;
|
||||||
|
@ -243,15 +280,19 @@ int setup_tests(void)
|
||||||
} else if (strcmp(p, "-dso_ref") == 0) {
|
} else if (strcmp(p, "-dso_ref") == 0) {
|
||||||
test_type = DSO_REFTEST;
|
test_type = DSO_REFTEST;
|
||||||
} else {
|
} else {
|
||||||
TEST_error("Unrecognised argument");
|
fprintf(stderr, "Unrecognised argument");
|
||||||
return 0;
|
return 1;
|
||||||
|
}
|
||||||
|
path_crypto = argv[2];
|
||||||
|
path_ssl = argv[3];
|
||||||
|
if (path_crypto == NULL || path_ssl == NULL) {
|
||||||
|
fprintf(stderr, "Invalid libcrypto/libssl path\n");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (!TEST_ptr(path_crypto = test_get_argument(1))
|
|
||||||
|| !TEST_ptr(path_ssl = test_get_argument(2)))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
#if defined(DSO_DLFCN) || defined(DSO_WIN32)
|
#if defined(DSO_DLFCN) || defined(DSO_WIN32)
|
||||||
ADD_TEST(test_lib);
|
if (!test_lib())
|
||||||
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue