mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 10:40:27 +09:00
tests: Cleanup OpenSSL in tests when GSSAPI is built
also from the fuzzer tests
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 08a32ac381)
This commit is contained in:
@@ -23,6 +23,11 @@ if (NOT WIN32)
|
|||||||
${TORTURE_LINK_LIBRARIES}
|
${TORTURE_LINK_LIBRARIES}
|
||||||
pthread)
|
pthread)
|
||||||
endif(NOT WIN32)
|
endif(NOT WIN32)
|
||||||
|
if (WITH_GSSAPI AND GSSAPI_FOUND)
|
||||||
|
set(TORTURE_LINK_LIBRARIES
|
||||||
|
${TORTURE_LINK_LIBRARIES}
|
||||||
|
crypto)
|
||||||
|
endif (WITH_GSSAPI AND GSSAPI_FOUND)
|
||||||
|
|
||||||
# create test library
|
# create test library
|
||||||
add_library(${TORTURE_LIBRARY}
|
add_library(${TORTURE_LIBRARY}
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ project(fuzzing CXX)
|
|||||||
|
|
||||||
macro(fuzzer name)
|
macro(fuzzer name)
|
||||||
add_executable(${name} ${name}.c)
|
add_executable(${name} ${name}.c)
|
||||||
target_link_libraries(${name}
|
target_link_libraries(${name} PRIVATE ${TORTURE_LINK_LIBRARIES})
|
||||||
PRIVATE
|
|
||||||
ssh::static pthread)
|
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
set_target_properties(${name}
|
set_target_properties(${name}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
/* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */
|
/* Simpler gnu89 version of StandaloneFuzzTargetMain.c from LLVM */
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
|
||||||
|
/* for OPENSSL_cleanup() of GSSAPI's OpenSSL context */
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
|
int LLVMFuzzerTestOneInput (const unsigned char *data, size_t size);
|
||||||
__attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv);
|
__attribute__((weak)) int LLVMFuzzerInitialize(int *argc, char ***argv);
|
||||||
@@ -35,5 +41,9 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
free (buf);
|
free (buf);
|
||||||
printf ("Done!\n");
|
printf ("Done!\n");
|
||||||
|
|
||||||
|
#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
|
||||||
|
OPENSSL_cleanup();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,11 @@
|
|||||||
#include <valgrind/valgrind.h>
|
#include <valgrind/valgrind.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_GSSAPI
|
||||||
|
/* for OPENSSL_cleanup() of GSSAPI's OpenSSL context */
|
||||||
|
#include <openssl/crypto.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TORTURE_SSHD_SRV_IPV4 "127.0.0.10"
|
#define TORTURE_SSHD_SRV_IPV4 "127.0.0.10"
|
||||||
/* socket wrapper IPv6 prefix fd00::5357:5fxx */
|
/* socket wrapper IPv6 prefix fd00::5357:5fxx */
|
||||||
#define TORTURE_SSHD_SRV_IPV6 "fd00::5357:5f0a"
|
#define TORTURE_SSHD_SRV_IPV6 "fd00::5357:5f0a"
|
||||||
@@ -1849,18 +1854,21 @@ __attribute__((weak)) int torture_run_tests(void)
|
|||||||
#endif /* defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) */
|
#endif /* defined(HAVE_WEAK_ATTRIBUTE) && defined(TORTURE_SHARED) */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finalize the torture context. No-op except for OpenSSL.
|
* Finalize the torture context. No-op except for OpenSSL or GSSAPI
|
||||||
*
|
*
|
||||||
* When OpenSSL is built without the at-exit handlers, it won't call the
|
* When OpenSSL is built without the at-exit handlers, it won't call the
|
||||||
* OPENSSL_cleanup() from destructor or at-exit handler, which means we need to
|
* OPENSSL_cleanup() from destructor or at-exit handler, which means we need to
|
||||||
* do it manually in the tests.
|
* do it manually in the tests.
|
||||||
*
|
*
|
||||||
* It is never a good idea to call this function from the library context as we
|
* It is never a good idea to call this function from the library context as we
|
||||||
* can not be sure the libssh is really the last one using the OpenSSL
|
* can not be sure the libssh is really the last one using the OpenSSL.
|
||||||
|
*
|
||||||
|
* This needs to be called at the end of the main function or any time before
|
||||||
|
* any forked process (servers) exits.
|
||||||
*/
|
*/
|
||||||
static void torture_finalize(void)
|
void torture_finalize(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCRYPTO
|
#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
|
||||||
OPENSSL_cleanup();
|
OPENSSL_cleanup();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,4 +178,6 @@ int torture_change_dir(char *path);
|
|||||||
void torture_setenv(char const* variable, char const* value);
|
void torture_setenv(char const* variable, char const* value);
|
||||||
void torture_unsetenv(char const* variable);
|
void torture_unsetenv(char const* variable);
|
||||||
|
|
||||||
|
void torture_finalize(void);
|
||||||
|
|
||||||
#endif /* _TORTURE_H */
|
#endif /* _TORTURE_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user