client: Check if the library is initialized in ssh_connect()
If the library is not initialized, SSH_ERROR is returned and the error message is set properly. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
0f33eecc01
Коммит
e3e3a27863
@ -509,6 +509,13 @@ int ssh_connect(ssh_session session)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!is_ssh_initialized()) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Library not initialized.");
|
||||
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
if (session == NULL) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
@ -183,6 +183,38 @@ static void torture_connect_socket(void **state) {
|
||||
assert_ssh_return_code(session, rc);
|
||||
}
|
||||
|
||||
static void torture_connect_uninitialized(UNUSED_PARAM(void **state))
|
||||
{
|
||||
int rc;
|
||||
ssh_session session;
|
||||
struct passwd *pwd;
|
||||
|
||||
/* Make sure the library is unitialized */
|
||||
while (is_ssh_initialized()) {
|
||||
rc = ssh_finalize();
|
||||
assert_return_code(rc, errno);
|
||||
}
|
||||
|
||||
pwd = getpwnam("bob");
|
||||
assert_non_null(pwd);
|
||||
|
||||
rc = setuid(pwd->pw_uid);
|
||||
assert_return_code(rc, errno);
|
||||
|
||||
session = ssh_new();
|
||||
assert_non_null(session);
|
||||
|
||||
rc = ssh_options_set(session, SSH_OPTIONS_HOST, TORTURE_SSH_SERVER);
|
||||
assert_ssh_return_code(session, rc);
|
||||
|
||||
/* Expect error from ssh_connect */
|
||||
rc = ssh_connect(session);
|
||||
assert_false(rc == SSH_OK);
|
||||
assert_string_equal(ssh_get_error(session), "Library not initialized.");
|
||||
|
||||
ssh_free(session);
|
||||
}
|
||||
|
||||
int torture_run_tests(void) {
|
||||
int rc;
|
||||
struct CMUnitTest tests[] = {
|
||||
@ -193,6 +225,7 @@ int torture_run_tests(void) {
|
||||
cmocka_unit_test_setup_teardown(torture_connect_timeout, session_setup, session_teardown),
|
||||
#endif
|
||||
cmocka_unit_test_setup_teardown(torture_connect_socket, session_setup, session_teardown),
|
||||
cmocka_unit_test(torture_connect_uninitialized),
|
||||
};
|
||||
|
||||
ssh_init();
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user