diff options
author | Andreas Schneider <asn@cynapses.org> | 2010-05-31 09:17:54 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cynapses.org> | 2010-05-31 09:17:54 +0200 |
commit | 560e93803804224c137d8dee6eae99ab2296734a (patch) | |
tree | daa9044a35ff95fda19d2c6d84925bde1cac24a1 | |
parent | 2a5d71971c9108d7b8e866c9f2364d4613bc22cb (diff) | |
download | libssh-560e93803804224c137d8dee6eae99ab2296734a.tar.gz libssh-560e93803804224c137d8dee6eae99ab2296734a.tar.xz libssh-560e93803804224c137d8dee6eae99ab2296734a.zip |
misc: Move size check down in ssh_path_expand_escape().
-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; } |