diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2019-07-30 15:02:46 +0100 |
---|---|---|
committer | Jakub Jelen <jjelen@redhat.com> | 2019-08-08 10:36:50 +0200 |
commit | 93113ccfb98901e5a53880fc0632278df22655fb (patch) | |
tree | 065b2dc94ec20c03c0a85387adb7054a1c0f8d9f | |
parent | 9ffaa12012b036e58d419ce4ddd3839bba14fecd (diff) | |
download | libssh-93113ccfb98901e5a53880fc0632278df22655fb.tar.gz libssh-93113ccfb98901e5a53880fc0632278df22655fb.tar.xz libssh-93113ccfb98901e5a53880fc0632278df22655fb.zip |
misc: Allow %% to escape a single % in paths.
For example "%d/config%%1" is expanded to "~/.ssh/config%1".
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 3737e5f0e75f355895bf0b46a33b1c1621477226)
-rw-r--r-- | src/misc.c | 3 | ||||
-rw-r--r-- | tests/unittests/torture_misc.c | 13 |
2 files changed, 16 insertions, 0 deletions
@@ -1127,6 +1127,7 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) { for (i = 0; *p != '\0'; p++) { if (*p != '%') { + escape: buf[i] = *p; i++; if (i >= MAX_BUF_SIZE) { @@ -1143,6 +1144,8 @@ char *ssh_path_expand_escape(ssh_session session, const char *s) { } switch (*p) { + case '%': + goto escape; case 'd': x = strdup(session->opts.sshdir); break; diff --git a/tests/unittests/torture_misc.c b/tests/unittests/torture_misc.c index bd7cffc6..2d628359 100644 --- a/tests/unittests/torture_misc.c +++ b/tests/unittests/torture_misc.c @@ -193,6 +193,18 @@ static void torture_path_expand_known_hosts(void **state) { free(tmp); } +static void torture_path_expand_percent(void **state) { + ssh_session session = *state; + char *tmp; + + session->opts.sshdir = strdup("/home/guru/.ssh"); + + tmp = ssh_path_expand_escape(session, "%d/config%%1"); + assert_non_null(tmp); + assert_string_equal(tmp, "/home/guru/.ssh/config%1"); + free(tmp); +} + static void torture_timeout_elapsed(void **state){ struct ssh_timestamp ts; (void) state; @@ -503,6 +515,7 @@ int torture_run_tests(void) { #endif cmocka_unit_test_setup_teardown(torture_path_expand_escape, setup, teardown), cmocka_unit_test_setup_teardown(torture_path_expand_known_hosts, setup, teardown), + cmocka_unit_test_setup_teardown(torture_path_expand_percent, setup, teardown), cmocka_unit_test(torture_timeout_elapsed), cmocka_unit_test(torture_timeout_update), cmocka_unit_test(torture_ssh_analyze_banner), |