diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-09-26 12:28:03 +0200 |
---|---|---|
committer | Aris Adamantiadis <aris@0xbadc0de.be> | 2009-09-26 12:28:03 +0200 |
commit | 2a2616f65ca8343b2a942bd150d38047cc8e3730 (patch) | |
tree | 46808d12edaeb32c34f56a34ce31b266582dc02e /libssh | |
parent | f643c34ee85f0542cbb8d9dc63703f61cc142238 (diff) | |
download | libssh-2a2616f65ca8343b2a942bd150d38047cc8e3730.tar.gz libssh-2a2616f65ca8343b2a942bd150d38047cc8e3730.tar.xz libssh-2a2616f65ca8343b2a942bd150d38047cc8e3730.zip |
Fix bug in dir_expand_sub
Diffstat (limited to 'libssh')
-rw-r--r-- | libssh/options.c | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/libssh/options.c b/libssh/options.c index 95bc0a2d..3c201260 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -237,38 +237,38 @@ static int ssh_options_set_algo(ssh_options opt, int algo, const char *list) { } static char *dir_expand_dup(ssh_options opt, const char *value, int allowsshdir) { - char *n; - - if (value[0] == '~' && value[1] == '/') { - const char *homedir = ssh_get_user_home_dir(); - size_t lv = strlen(value + 1), lh = strlen(homedir); - - n = malloc(lv + lh + 1); - if (n == NULL) - return NULL; - memcpy(n, homedir, lh); - memcpy(n + lh + 1, value + 1, lv + 1); - return n; - } - if (allowsshdir && strncmp(value, "SSH_DIR/", 8) == 0) { - size_t lv, ls; - if (opt->ssh_dir == NULL) { - if (ssh_options_set(opt, SSH_OPTIONS_SSH_DIR, NULL) < 0) - return NULL; - } - - value += 7; - lv = strlen(value); - ls = strlen(opt->ssh_dir); - - n = malloc(lv + ls + 1); - if (n == NULL) - return NULL; - memcpy(n, opt->ssh_dir, ls); - memcpy(n + ls + 1, value, lv + 1); - return n; - } - return strdup(value); + char *new; + + if (value[0] == '~' && value[1] == '/') { + const char *homedir = ssh_get_user_home_dir(); + size_t lv = strlen(value + 1), lh = strlen(homedir); + + new = malloc(lv + lh + 1); + if (new == NULL) + return NULL; + memcpy(new, homedir, lh); + memcpy(new + lh, value + 1, lv + 1); + return new; + } + if (allowsshdir && strncmp(value, "SSH_DIR/", 8) == 0) { + size_t lv, ls; + if (opt->ssh_dir == NULL) { + if (ssh_options_set(opt, SSH_OPTIONS_SSH_DIR, NULL) < 0) + return NULL; + } + + value += 7; + lv = strlen(value); + ls = strlen(opt->ssh_dir); + + new = malloc(lv + ls + 1); + if (new == NULL) + return NULL; + memcpy(new, opt->ssh_dir, ls); + memcpy(new + ls, value, lv + 1); + return new; + } + return strdup(value); } /** |