Fix bug in dir_expand_sub

This commit is contained in:
Aris Adamantiadis
2009-09-26 12:28:03 +02:00
parent f643c34ee8
commit 2a2616f65c

View File

@@ -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) { static char *dir_expand_dup(ssh_options opt, const char *value, int allowsshdir) {
char *n; char *new;
if (value[0] == '~' && value[1] == '/') { if (value[0] == '~' && value[1] == '/') {
const char *homedir = ssh_get_user_home_dir(); const char *homedir = ssh_get_user_home_dir();
size_t lv = strlen(value + 1), lh = strlen(homedir); size_t lv = strlen(value + 1), lh = strlen(homedir);
n = malloc(lv + lh + 1); new = malloc(lv + lh + 1);
if (n == NULL) if (new == NULL)
return NULL; return NULL;
memcpy(n, homedir, lh); memcpy(new, homedir, lh);
memcpy(n + lh + 1, value + 1, lv + 1); memcpy(new + lh, value + 1, lv + 1);
return n; return new;
} }
if (allowsshdir && strncmp(value, "SSH_DIR/", 8) == 0) { if (allowsshdir && strncmp(value, "SSH_DIR/", 8) == 0) {
size_t lv, ls; size_t lv, ls;
if (opt->ssh_dir == NULL) { if (opt->ssh_dir == NULL) {
if (ssh_options_set(opt, SSH_OPTIONS_SSH_DIR, NULL) < 0) if (ssh_options_set(opt, SSH_OPTIONS_SSH_DIR, NULL) < 0)
return NULL; return NULL;
} }
value += 7; value += 7;
lv = strlen(value); lv = strlen(value);
ls = strlen(opt->ssh_dir); ls = strlen(opt->ssh_dir);
n = malloc(lv + ls + 1); new = malloc(lv + ls + 1);
if (n == NULL) if (new == NULL)
return NULL; return NULL;
memcpy(n, opt->ssh_dir, ls); memcpy(new, opt->ssh_dir, ls);
memcpy(n + ls + 1, value, lv + 1); memcpy(new + ls, value, lv + 1);
return n; return new;
} }
return strdup(value); return strdup(value);
} }
/** /**