aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2013-07-14 14:58:57 +0200
committerAndreas Schneider <asn@cryptomilk.org>2013-07-14 15:02:11 +0200
commit776ff528df2e363fd12a8fbaae2489956f676bee (patch)
tree4a87ee5f3ad9fc3ad9c473de5bc2fe86ef406db7 /examples
parent22e88581346acfe0360cf6efebba3ed0c2842d01 (diff)
downloadlibssh-776ff528df2e363fd12a8fbaae2489956f676bee.tar.gz
libssh-776ff528df2e363fd12a8fbaae2489956f676bee.tar.xz
libssh-776ff528df2e363fd12a8fbaae2489956f676bee.zip
examples: Make sure we have a valid scp pointer.
CID #1032343
Diffstat (limited to 'examples')
-rw-r--r--examples/libssh_scp.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/examples/libssh_scp.c b/examples/libssh_scp.c
index b7471da6..9027ef99 100644
--- a/examples/libssh_scp.c
+++ b/examples/libssh_scp.c
@@ -84,9 +84,15 @@ static int opts(int argc, char **argv){
}
static struct location *parse_location(char *loc){
- struct location *location=malloc(sizeof(struct location));
+ struct location *location;
char *ptr;
+ location = malloc(sizeof(struct location));
+ if (location == NULL) {
+ return NULL;
+ }
+ memset(location, 0, sizeof(struct location));
+
location->host=location->user=NULL;
ptr=strchr(loc,':');
if(ptr != NULL){
@@ -123,6 +129,7 @@ static int open_location(struct location *loc, int flag){
if(ssh_scp_init(loc->scp)==SSH_ERROR){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
ssh_scp_free(loc->scp);
+ loc->scp = NULL;
return -1;
}
return 0;
@@ -140,6 +147,7 @@ static int open_location(struct location *loc, int flag){
if(ssh_scp_init(loc->scp)==SSH_ERROR){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
ssh_scp_free(loc->scp);
+ loc->scp = NULL;
return -1;
}
return 0;