diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-10-15 14:53:11 +0200 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-10-15 14:53:11 +0200 |
commit | cbf012c33722737c255d08c7f81a3ee5c6c19052 (patch) | |
tree | ff94b8a3aaa3c239dcfe85715b4eba5034a5b9d6 /libssh/options.c | |
parent | c360ed1d9ad4ee0a65dd80494605c55802c30ba3 (diff) | |
download | libssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.tar.gz libssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.tar.xz libssh-cbf012c33722737c255d08c7f81a3ee5c6c19052.zip |
Fixed ssh_get_home_dir and ssh dir to be more portable on UNIX systems.
Thanks to Pino Toscano.
Diffstat (limited to 'libssh/options.c')
-rw-r--r-- | libssh/options.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libssh/options.c b/libssh/options.c index 08b78f7..d506981 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -163,15 +163,23 @@ static char *dir_expand_dup(ssh_session session, const char *value, int allowssh char *new; if (value[0] == '~' && value[1] == '/') { - const char *homedir = ssh_get_user_home_dir(); - size_t lv = strlen(value + 1), lh = strlen(homedir); + char *homedir = ssh_get_user_home_dir(); + size_t lv, lh; + + if (homedir == NULL) { + return NULL; + } + lv = strlen(value + 1); + lh = strlen(homedir); new = malloc(lv + lh + 1); if (new == NULL) { ssh_set_error_oom(session); + SAFE_FREE(homedir); return NULL; } memcpy(new, homedir, lh); + SAFE_FREE(homedir); memcpy(new + lh, value + 1, lv + 1); return new; } |