1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-24 19:37:48 +03:00

misc: Move size check down in ssh_path_expand_escape().

This commit is contained in:
Andreas Schneider
2010-05-31 09:17:54 +02:00
parent 2a5d71971c
commit 560e938038
3 changed files with 21 additions and 6 deletions

View File

@@ -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';

View File

@@ -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;
}

View File

@@ -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;
}