diff options
-rw-r--r-- | libssh/misc.c | 11 | ||||
-rw-r--r-- | libssh/options.c | 2 | ||||
-rw-r--r-- | tests/unittests/torture_misc.c | 14 |
3 files changed, 21 insertions, 6 deletions
diff --git a/libssh/misc.c b/libssh/misc.c index c971367b..555c25b4 100644 --- a/libssh/misc.c +++ b/libssh/misc.c @@ -597,17 +597,18 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) { const char *p; size_t i, l; - if (strlen(s) > MAX_BUF_SIZE) { - ssh_set_error(session, SSH_FATAL, "string to expand too long"); - return NULL; - } - r = ssh_path_expand_tilde(s); if (r == NULL) { ssh_set_error_oom(session); return NULL; } + if (strlen(r) > MAX_BUF_SIZE) { + ssh_set_error(session, SSH_FATAL, "string to expand too long"); + free(r); + return NULL; + } + p = r; buf[0] = '\0'; diff --git a/libssh/options.c b/libssh/options.c index 4fdd5dc8..f87af587 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -425,7 +425,7 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type, if (value == NULL) { SAFE_FREE(session->sshdir); - session->sshdir = ssh_path_expand_tilde("~/.ssh/"); + session->sshdir = ssh_path_expand_tilde("~/.ssh"); if (session->sshdir == NULL) { return -1; } diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index 5996bd97..e9161073 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -117,6 +117,18 @@ START_TEST (torture_path_expand_escape) } END_TEST +START_TEST (torture_path_expand_known_hosts) +{ + char *tmp; + + ssh_options_set(session, SSH_OPTIONS_SSH_DIR, "/home/guru/.ssh"); + + tmp = ssh_path_expand_escape(session, "%d/known_hosts"); + ck_assert_str_eq(tmp, "/home/guru/.ssh/known_hosts"); + free(tmp); +} +END_TEST + Suite *torture_make_suite(void) { Suite *s = suite_create("libssh_misc"); @@ -127,6 +139,8 @@ Suite *torture_make_suite(void) { torture_create_case(s, "torture_path_expand_tilde", torture_path_expand_tilde); torture_create_case_fixture(s, "torture_path_expand_escape", torture_path_expand_escape, setup, teardown); + torture_create_case_fixture(s, "torture_path_expand_known_hosts", + torture_path_expand_known_hosts, setup, teardown); return s; } |