mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
tests: Cleanup OpenSSL in the forked server processes
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 7eefbbd478)
This commit is contained in:
@@ -11,7 +11,8 @@ set(server_SRCS
|
||||
add_library(testserver STATIC
|
||||
test_server.c
|
||||
default_cb.c
|
||||
sftpserver_cb.c)
|
||||
sftpserver_cb.c
|
||||
testserver_common.c)
|
||||
if (WITH_COVERAGE)
|
||||
append_coverage_compiler_flags_to_target(testserver)
|
||||
endif (WITH_COVERAGE)
|
||||
@@ -32,7 +33,7 @@ if (UNIX AND NOT WIN32)
|
||||
add_executable(test_server ${server_SRCS})
|
||||
target_compile_options(test_server PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
|
||||
target_link_libraries(test_server
|
||||
PRIVATE testserver ssh::ssh ${ARGP_LIBRARIES} util)
|
||||
PRIVATE testserver ${TORTURE_LINK_LIBRARIES} ${ARGP_LIBRARIES} util)
|
||||
if (WITH_COVERAGE)
|
||||
append_coverage_compiler_flags_to_target(test_server)
|
||||
endif (WITH_COVERAGE)
|
||||
|
||||
@@ -21,9 +21,11 @@
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "config.h"
|
||||
#include "test_server.h"
|
||||
#include "default_cb.h"
|
||||
#include "testserver_common.h"
|
||||
|
||||
#include <libssh/callbacks.h>
|
||||
#include <libssh/server.h>
|
||||
@@ -448,9 +450,11 @@ static int exec_pty(const char *mode,
|
||||
case 0:
|
||||
close(cdata->pty_master);
|
||||
if (login_tty(cdata->pty_slave) != 0) {
|
||||
finalize_openssl();
|
||||
exit(1);
|
||||
}
|
||||
execl("/bin/sh", "sh", mode, command, NULL);
|
||||
finalize_openssl();
|
||||
exit(0);
|
||||
default:
|
||||
close(cdata->pty_slave);
|
||||
@@ -500,6 +504,7 @@ static int exec_nopty(const char *command, struct channel_data_st *cdata)
|
||||
close(err[1]);
|
||||
/* exec the requested command. */
|
||||
execl("/bin/sh", "sh", "-c", command, NULL);
|
||||
finalize_openssl();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
|
||||
#include "test_server.h"
|
||||
#include "testserver_common.h"
|
||||
|
||||
#include <libssh/priv.h>
|
||||
#include <libssh/libssh.h>
|
||||
@@ -288,6 +289,7 @@ int run_server(struct server_state_st *state)
|
||||
|
||||
free_server_state(state);
|
||||
SAFE_FREE(state);
|
||||
finalize_openssl();
|
||||
exit(0);
|
||||
case -1:
|
||||
fprintf(stderr, "Failed to fork\n");
|
||||
@@ -355,11 +357,8 @@ fork_run_server(struct server_state_st *state,
|
||||
|
||||
/* The child process starts a server which will listen for connections */
|
||||
rc = run_server(state);
|
||||
if (rc != 0) {
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
finalize_openssl();
|
||||
exit(rc);
|
||||
case -1:
|
||||
strerror_r(errno, err_str, 1024);
|
||||
fprintf(stderr, "Failed to fork: %s\n",
|
||||
|
||||
36
tests/server/test_server/testserver_common.c
Normal file
36
tests/server/test_server/testserver_common.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2025 by Red Hat, Inc.
|
||||
*
|
||||
* Author: Jakub Jelen <jjelen@redhat.com>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "testserver_common.h"
|
||||
|
||||
#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
|
||||
/* for OPENSSL_cleanup() of GSSAPI's OpenSSL context */
|
||||
#include <openssl/crypto.h>
|
||||
#endif
|
||||
|
||||
void finalize_openssl(void)
|
||||
{
|
||||
#if defined(HAVE_LIBCRYPTO) || defined(WITH_GSSAPI)
|
||||
OPENSSL_cleanup();
|
||||
#endif
|
||||
}
|
||||
26
tests/server/test_server/testserver_common.h
Normal file
26
tests/server/test_server/testserver_common.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* This file is part of the SSH Library
|
||||
*
|
||||
* Copyright (c) 2025 by Red Hat, Inc.
|
||||
*
|
||||
* Author: Jakub Jelen <jjelen@redhat.com>
|
||||
*
|
||||
* The SSH Library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* The SSH Library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with the SSH Library; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||
* MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
void finalize_openssl(void);
|
||||
Reference in New Issue
Block a user