mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
misc: Move size check down in ssh_path_expand_escape().
This commit is contained in:
@@ -597,17 +597,18 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) {
|
|||||||
const char *p;
|
const char *p;
|
||||||
size_t i, l;
|
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);
|
r = ssh_path_expand_tilde(s);
|
||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
ssh_set_error_oom(session);
|
ssh_set_error_oom(session);
|
||||||
return NULL;
|
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;
|
p = r;
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
|
|
||||||
|
|||||||
@@ -425,7 +425,7 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
|||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
SAFE_FREE(session->sshdir);
|
SAFE_FREE(session->sshdir);
|
||||||
|
|
||||||
session->sshdir = ssh_path_expand_tilde("~/.ssh/");
|
session->sshdir = ssh_path_expand_tilde("~/.ssh");
|
||||||
if (session->sshdir == NULL) {
|
if (session->sshdir == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,18 @@ START_TEST (torture_path_expand_escape)
|
|||||||
}
|
}
|
||||||
END_TEST
|
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 *torture_make_suite(void) {
|
||||||
Suite *s = suite_create("libssh_misc");
|
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(s, "torture_path_expand_tilde", torture_path_expand_tilde);
|
||||||
torture_create_case_fixture(s, "torture_path_expand_escape",
|
torture_create_case_fixture(s, "torture_path_expand_escape",
|
||||||
torture_path_expand_escape, setup, teardown);
|
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;
|
return s;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user