1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

options: Allocate dest in ssh_options_copy().

This commit is contained in:
Andreas Schneider
2011-08-11 12:53:02 +02:00
parent 1c30c2a510
commit a4a1af5bbf

View File

@@ -53,7 +53,8 @@
*
* @param src The session to use to copy the options.
*
* @param dest The session to copy the options to.
* @param dest A pointer to store the allocated session with duplicated
* options. You have to free the memory.
*
* @returns 0 on sucess, -1 on error with errno set.
*
@@ -63,15 +64,19 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
ssh_session new;
int i;
if (src == NULL || dest == NULL || *dest == NULL) {
if (src == NULL || dest == NULL) {
return -1;
}
new = *dest;
new = ssh_new();
if (new == NULL) {
return -1;
}
if (src->username) {
new->username = strdup(src->username);
if (new->username == NULL) {
ssh_free(new);
return -1;
}
}
@@ -79,6 +84,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
if (src->host) {
new->host = strdup(src->host);
if (new->host == NULL) {
ssh_free(new);
return -1;
}
}
@@ -88,6 +94,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
new->identity = ssh_list_new();
if (new->identity == NULL) {
ssh_free(new);
return -1;
}
@@ -98,11 +105,13 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
id = strdup((char *) it->data);
if (id == NULL) {
ssh_free(new);
return -1;
}
rc = ssh_list_append(new->identity, id);
if (rc < 0) {
ssh_free(new);
return -1;
}
it = it->next;
@@ -112,6 +121,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
if (src->sshdir) {
new->sshdir = strdup(src->sshdir);
if (new->sshdir == NULL) {
ssh_free(new);
return -1;
}
}
@@ -119,6 +129,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
if (src->knownhosts) {
new->knownhosts = strdup(src->knownhosts);
if (new->knownhosts == NULL) {
ssh_free(new);
return -1;
}
}
@@ -127,6 +138,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
if (src->wanted_methods[i]) {
new->wanted_methods[i] = strdup(src->wanted_methods[i]);
if (new->wanted_methods[i] == NULL) {
ssh_free(new);
return -1;
}
}
@@ -135,6 +147,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
if(src->ProxyCommand) {
new->ProxyCommand = strdup(src->ProxyCommand);
if(new->ProxyCommand == NULL)
ssh_free(new);
return -1;
}
new->fd = src->fd;
@@ -147,6 +160,8 @@ int ssh_options_copy(ssh_session src, ssh_session *dest) {
new->common.log_verbosity = src->common.log_verbosity;
new->compressionlevel = src->compressionlevel;
*dest = new;
return 0;
}