summaryrefslogtreecommitdiff
path: root/libs/libssh2/src/sftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libssh2/src/sftp.c')
-rw-r--r--libs/libssh2/src/sftp.c846
1 files changed, 466 insertions, 380 deletions
diff --git a/libs/libssh2/src/sftp.c b/libs/libssh2/src/sftp.c
index fd94d39029..ece590e51f 100644
--- a/libs/libssh2/src/sftp.c
+++ b/libs/libssh2/src/sftp.c
@@ -1,6 +1,6 @@
/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2007 Eli Fant <elifantu@mail.ru>
- * Copyright (c) 2009-2014 by Daniel Stenberg
+ * Copyright (c) 2009-2019 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@@ -91,7 +91,7 @@
/* This is the maximum packet length to accept, as larger than this indicate
some kind of server problem. */
-#define LIBSSH2_SFTP_PACKET_MAXLEN 80000
+#define LIBSSH2_SFTP_PACKET_MAXLEN (256 * 1024)
static int sftp_packet_ask(LIBSSH2_SFTP *sftp, unsigned char packet_type,
uint32_t request_id, unsigned char **data,
@@ -161,7 +161,8 @@ remove_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id)
request_id);
if(zombie) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
- "Removing request ID %ld from the list of zombie requests",
+ "Removing request ID %ld from the list of "
+ "zombie requests",
request_id);
_libssh2_list_remove(&zombie->node);
@@ -181,7 +182,7 @@ add_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id)
zombie = LIBSSH2_ALLOC(sftp->channel->session,
sizeof(struct sftp_zombie_requests));
- if (!zombie)
+ if(!zombie)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"malloc fail for zombie request ID");
else {
@@ -204,7 +205,7 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data,
LIBSSH2_SFTP_PACKET *packet;
uint32_t request_id;
- if (data_len < 5) {
+ if(data_len < 5) {
return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
}
@@ -272,7 +273,7 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data,
}
packet = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_SFTP_PACKET));
- if (!packet) {
+ if(!packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate datablock for SFTP packet");
}
@@ -331,9 +332,9 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
(char *)&sftp->partial_size[
sftp->partial_size_len],
4 - sftp->partial_size_len);
- if (rc == LIBSSH2_ERROR_EAGAIN)
+ if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
- else if (rc < 0)
+ else if(rc < 0)
return _libssh2_error(session, rc, "channel read");
sftp->partial_size_len += rc;
@@ -345,11 +346,15 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
sftp->partial_len = _libssh2_ntohu32(sftp->partial_size);
/* make sure we don't proceed if the packet size is unreasonably
large */
- if (sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN)
+ if(sftp->partial_len > LIBSSH2_SFTP_PACKET_MAXLEN) {
+ libssh2_channel_flush(channel);
+ sftp->partial_size_len = 0;
return _libssh2_error(session,
LIBSSH2_ERROR_CHANNEL_PACKET_EXCEEDED,
"SFTP packet too large");
- if (sftp->partial_len == 0)
+ }
+
+ if(sftp->partial_len == 0)
return _libssh2_error(session,
LIBSSH2_ERROR_ALLOC,
"Unable to allocate empty SFTP packet");
@@ -358,7 +363,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
"Data begin - Packet Length: %lu",
sftp->partial_len);
packet = LIBSSH2_ALLOC(session, sftp->partial_len);
- if (!packet)
+ if(!packet)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate SFTP packet");
sftp->partial_size_len = 0;
@@ -372,7 +377,8 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
if(sftp->partial_len > recv_window) {
/* ask for twice the data amount we need at once */
rc = _libssh2_channel_receive_window_adjust(channel,
- sftp->partial_len*2,
+ sftp->partial_len
+ * 2,
1, NULL);
/* store the state so that we continue with the correct
operation at next invoke */
@@ -386,13 +392,13 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
}
/* Read as much of the packet as we can */
- while (sftp->partial_len > sftp->partial_received) {
+ while(sftp->partial_len > sftp->partial_received) {
rc = _libssh2_channel_read(channel, 0,
(char *)&packet[sftp->partial_received],
sftp->partial_len -
sftp->partial_received);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
/*
* We received EAGAIN, save what we have and return EAGAIN to
* the caller. Set 'partial_packet' so that this function
@@ -401,7 +407,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
sftp->packet_state = libssh2_NB_state_sent1;
return rc;
}
- else if (rc < 0) {
+ else if(rc < 0) {
LIBSSH2_FREE(session, packet);
sftp->partial_packet = NULL;
return _libssh2_error(session, rc,
@@ -416,7 +422,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp)
so we take a copy of the packet type before we call it. */
packet_type = packet[0];
rc = sftp_packet_add(sftp, packet, sftp->partial_len);
- if (rc) {
+ if(rc) {
LIBSSH2_FREE(session, packet);
return rc;
}
@@ -485,7 +491,7 @@ sftp_packet_ask(LIBSSH2_SFTP *sftp, unsigned char packet_type,
/* Special consideration when getting VERSION packet */
- while (packet) {
+ while(packet) {
if((packet->data[0] == packet_type) &&
((packet_type == SSH_FXP_VERSION) ||
(packet->request_id == request_id))) {
@@ -517,38 +523,38 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type,
LIBSSH2_SESSION *session = sftp->channel->session;
int rc;
- if (data == NULL || data_len == NULL || required_size == 0) {
+ if(data == NULL || data_len == NULL || required_size == 0) {
return LIBSSH2_ERROR_BAD_USE;
}
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Requiring packet %d id %ld",
(int) packet_type, request_id);
- if (sftp_packet_ask(sftp, packet_type, request_id, data, data_len) == 0) {
+ if(sftp_packet_ask(sftp, packet_type, request_id, data, data_len) == 0) {
/* The right packet was available in the packet brigade */
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got %d",
(int) packet_type);
if (*data_len < required_size) {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
return LIBSSH2_ERROR_NONE;
}
- while (session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
+ while(session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
rc = sftp_packet_read(sftp);
- if (rc < 0)
+ if(rc < 0)
return rc;
/* data was read, check the queue again */
- if (!sftp_packet_ask(sftp, packet_type, request_id, data, data_len)) {
+ if(!sftp_packet_ask(sftp, packet_type, request_id, data, data_len)) {
/* The right packet was available in the packet brigade */
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Got %d",
(int) packet_type);
if (*data_len < required_size) {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
return LIBSSH2_ERROR_NONE;
@@ -571,17 +577,17 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
int i;
int rc;
- if (data == NULL || data_len == NULL || required_size == 0) {
+ if(data == NULL || data_len == NULL || required_size == 0) {
return LIBSSH2_ERROR_BAD_USE;
}
/* If no timeout is active, start a new one */
- if (sftp->requirev_start == 0)
+ if(sftp->requirev_start == 0)
sftp->requirev_start = time(NULL);
- while (sftp->channel->session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
+ while(sftp->channel->session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
for(i = 0; i < num_valid_responses; i++) {
- if (sftp_packet_ask(sftp, valid_responses[i], request_id,
+ if(sftp_packet_ask(sftp, valid_responses[i], request_id,
data, data_len) == 0) {
/*
* Set to zero before all returns to say
@@ -590,7 +596,7 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
sftp->requirev_start = 0;
if (*data_len < required_size) {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
return LIBSSH2_ERROR_NONE;
@@ -598,19 +604,21 @@ sftp_packet_requirev(LIBSSH2_SFTP *sftp, int num_valid_responses,
}
rc = sftp_packet_read(sftp);
- if ((rc < 0) && (rc != LIBSSH2_ERROR_EAGAIN)) {
+ if((rc < 0) && (rc != LIBSSH2_ERROR_EAGAIN)) {
sftp->requirev_start = 0;
return rc;
- } else if (rc <= 0) {
+ }
+ else if(rc <= 0) {
/* prevent busy-looping */
long left =
- LIBSSH2_READ_TIMEOUT - (long)(time(NULL) - sftp->requirev_start);
+ LIBSSH2_READ_TIMEOUT -
+ (long)(time(NULL) - sftp->requirev_start);
- if (left <= 0) {
+ if(left <= 0) {
sftp->requirev_start = 0;
return LIBSSH2_ERROR_TIMEOUT;
}
- else if (rc == LIBSSH2_ERROR_EAGAIN) {
+ else if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
}
@@ -636,27 +644,27 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs)
/* TODO: When we add SFTP4+ functionality flag_mask can get additional
bits */
- if (!attrs) {
+ if(!attrs) {
_libssh2_htonu32(s, 0);
return 4;
}
_libssh2_store_u32(&s, attrs->flags & flag_mask);
- if (attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
_libssh2_store_u64(&s, attrs->filesize);
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
_libssh2_store_u32(&s, attrs->uid);
_libssh2_store_u32(&s, attrs->gid);
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
_libssh2_store_u32(&s, attrs->permissions);
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
_libssh2_store_u32(&s, attrs->atime);
_libssh2_store_u32(&s, attrs->mtime);
}
@@ -667,68 +675,57 @@ sftp_attr2bin(unsigned char *p, const LIBSSH2_SFTP_ATTRIBUTES * attrs)
/* sftp_bin2attr
*/
static int
-sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES * attrs, const unsigned char *p, size_t data_len)
+sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
+ size_t data_len)
{
- const unsigned char *s = p;
+ struct string_buf buf;
+ uint32_t flags = 0;
+ buf.data = (unsigned char *)p;
+ buf.dataptr = buf.data;
+ buf.len = data_len;
- if (data_len >= 4) {
- memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
- attrs->flags = _libssh2_ntohu32(s);
- s += 4;
- data_len -= 4;
- }
- else {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ if(_libssh2_get_u32(&buf, &flags) != 0) {
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
+ attrs->flags = flags;
- if (attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
- if (data_len >= 8) {
- attrs->filesize = _libssh2_ntohu64(s);
- s += 8;
- data_len -= 8;
- }
- else {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) {
+ if(_libssh2_get_u64(&buf, &(attrs->filesize)) != 0) {
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
- if (data_len >= 8) {
- attrs->uid = _libssh2_ntohu32(s);
- s += 4;
- attrs->gid = _libssh2_ntohu32(s);
- s += 4;
- data_len -= 8;
- }
- else {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) {
+ uint32_t uid = 0;
+ uint32_t gid = 0;
+ if(_libssh2_get_u32(&buf, &uid) != 0 ||
+ _libssh2_get_u32(&buf, &gid) != 0) {
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
+ attrs->uid = uid;
+ attrs->gid = gid;
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
- if (data_len >= 4) {
- attrs->permissions = _libssh2_ntohu32(s);
- s += 4;
- data_len -= 4;
- }
- else {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) {
+ uint32_t permissions;
+ if(_libssh2_get_u32(&buf, &permissions) != 0) {
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
+ attrs->permissions = permissions;
}
- if (attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
- if (data_len >= 8) {
- attrs->atime = _libssh2_ntohu32(s);
- s += 4;
- attrs->mtime = _libssh2_ntohu32(s);
- s += 4;
- }
- else {
- return LIBSSH2_ERROR_OUT_OF_BOUNDARY;
+ if(attrs->flags & LIBSSH2_SFTP_ATTR_ACMODTIME) {
+ uint32_t atime;
+ uint32_t mtime;
+ if(_libssh2_get_u32(&buf, &atime) != 0 ||
+ _libssh2_get_u32(&buf, &mtime) != 0) {
+ return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
}
+ attrs->atime = atime;
+ attrs->mtime = mtime;
}
- return (s - p);
+ return (buf.dataptr - buf.data);
}
/* ************
@@ -748,12 +745,12 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor)
(void) channel;
/* Free the partial packet storage for sftp_packet_read */
- if (sftp->partial_packet) {
+ if(sftp->partial_packet) {
LIBSSH2_FREE(session, sftp->partial_packet);
}
/* Free the packet storage for _libssh2_sftp_packet_readdir */
- if (sftp->readdir_packet) {
+ if(sftp->readdir_packet) {
LIBSSH2_FREE(session, sftp->readdir_packet);
}
@@ -767,12 +764,14 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor)
*/
static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
{
- unsigned char *data, *s;
+ unsigned char *data;
size_t data_len;
ssize_t rc;
LIBSSH2_SFTP *sftp_handle;
+ struct string_buf buf;
+ unsigned char *endp;
- if (session->sftpInit_state == libssh2_NB_state_idle) {
+ if(session->sftpInit_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Initializing SFTP subsystem");
@@ -795,13 +794,13 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
sftp_handle = session->sftpInit_sftp;
- if (session->sftpInit_state == libssh2_NB_state_created) {
+ if(session->sftpInit_state == libssh2_NB_state_created) {
session->sftpInit_channel =
_libssh2_channel_open(session, "session", sizeof("session") - 1,
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
- if (!session->sftpInit_channel) {
- if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
+ if(!session->sftpInit_channel) {
+ if(libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block starting up channel");
}
@@ -816,16 +815,18 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
session->sftpInit_state = libssh2_NB_state_sent;
}
- if (session->sftpInit_state == libssh2_NB_state_sent) {
+ if(session->sftpInit_state == libssh2_NB_state_sent) {
int ret = _libssh2_channel_process_startup(session->sftpInit_channel,
"subsystem",
- sizeof("subsystem") - 1, "sftp",
+ sizeof("subsystem") - 1,
+ "sftp",
strlen("sftp"));
- if (ret == LIBSSH2_ERROR_EAGAIN) {
+ if(ret == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block to request SFTP subsystem");
return NULL;
- } else if (ret) {
+ }
+ else if(ret) {
_libssh2_error(session, LIBSSH2_ERROR_CHANNEL_FAILURE,
"Unable to request SFTP subsystem");
goto sftp_init_error;
@@ -834,10 +835,10 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
session->sftpInit_state = libssh2_NB_state_sent1;
}
- if (session->sftpInit_state == libssh2_NB_state_sent1) {
+ if(session->sftpInit_state == libssh2_NB_state_sent1) {
rc = _libssh2_channel_extended_data(session->sftpInit_channel,
- LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE);
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting handle extended data");
return NULL;
@@ -846,7 +847,7 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
sftp_handle =
session->sftpInit_sftp =
LIBSSH2_CALLOC(session, sizeof(LIBSSH2_SFTP));
- if (!sftp_handle) {
+ if(!sftp_handle) {
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate a new SFTP structure");
goto sftp_init_error;
@@ -860,19 +861,20 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
session->sftpInit_sent = 0; /* nothing's sent yet */
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
- "Sending FXP_INIT packet advertising version %d support",
+ "Sending FXP_INIT packet advertising "
+ "version %d support",
(int) LIBSSH2_SFTP_VERSION);
session->sftpInit_state = libssh2_NB_state_sent2;
}
- if (session->sftpInit_state == libssh2_NB_state_sent2) {
+ if(session->sftpInit_state == libssh2_NB_state_sent2) {
/* sent off what's left of the init buffer to send */
rc = _libssh2_channel_write(session->sftpInit_channel, 0,
session->sftpInit_buffer +
session->sftpInit_sent,
9 - session->sftpInit_sent);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending SSH_FXP_INIT");
return NULL;
@@ -896,29 +898,37 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
rc = sftp_packet_require(sftp_handle, SSH_FXP_VERSION,
0, &data, &data_len, 5);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block receiving SSH_FXP_VERSION");
return NULL;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid SSH_FXP_VERSION response");
goto sftp_init_error;
}
- else if (rc) {
+ else if(rc) {
_libssh2_error(session, rc,
"Timeout waiting for response from SFTP subsystem");
goto sftp_init_error;
}
- s = data + 1;
- sftp_handle->version = _libssh2_ntohu32(s);
- s += 4;
- if (sftp_handle->version > LIBSSH2_SFTP_VERSION) {
+ buf.data = data;
+ buf.dataptr = buf.data + 1;
+ buf.len = data_len;
+ endp = &buf.data[data_len];
+
+ if(_libssh2_get_u32(&buf, &(sftp_handle->version)) != 0) {
+ LIBSSH2_FREE(session, data);
+ rc = LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto sftp_init_error;
+ }
+
+ if(sftp_handle->version > LIBSSH2_SFTP_VERSION) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Truncating remote SFTP version from %lu",
sftp_handle->version);
@@ -927,20 +937,22 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Enabling SFTP version %lu compatibility",
sftp_handle->version);
- while (s < (data + data_len)) {
- size_t extname_len, extdata_len;
-
- extname_len = _libssh2_ntohu32(s);
- s += 4;
- /* the extension name starts here */
- s += extname_len;
-
- extdata_len = _libssh2_ntohu32(s);
- s += 4;
+ while(buf.dataptr < endp) {
+ unsigned char *extname, *extdata;
- /* TODO: Actually process extensions */
- s += extdata_len;
+ if(_libssh2_get_string(&buf, &extname, NULL)) {
+ LIBSSH2_FREE(session, data);
+ _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
+ "Data too short when extracting extname");
+ goto sftp_init_error;
+ }
+ if(_libssh2_get_string(&buf, &extdata, NULL)) {
+ LIBSSH2_FREE(session, data);
+ _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL,
+ "Data too short when extracting extdata");
+ goto sftp_init_error;
+ }
}
LIBSSH2_FREE(session, data);
@@ -960,10 +972,10 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session)
return sftp_handle;
sftp_init_error:
- while (_libssh2_channel_free(session->sftpInit_channel) ==
+ while(_libssh2_channel_free(session->sftpInit_channel) ==
LIBSSH2_ERROR_EAGAIN);
session->sftpInit_channel = NULL;
- if (session->sftpInit_sftp) {
+ if(session->sftpInit_sftp) {
LIBSSH2_FREE(session, session->sftpInit_sftp);
session->sftpInit_sftp = NULL;
}
@@ -1006,55 +1018,55 @@ sftp_shutdown(LIBSSH2_SFTP *sftp)
/*
* Make sure all memory used in the state variables are free
*/
- if (sftp->partial_packet) {
+ if(sftp->partial_packet) {
LIBSSH2_FREE(session, sftp->partial_packet);
sftp->partial_packet = NULL;
}
- if (sftp->open_packet) {
+ if(sftp->open_packet) {
LIBSSH2_FREE(session, sftp->open_packet);
sftp->open_packet = NULL;
}
- if (sftp->readdir_packet) {
+ if(sftp->readdir_packet) {
LIBSSH2_FREE(session, sftp->readdir_packet);
sftp->readdir_packet = NULL;
}
- if (sftp->fstat_packet) {
+ if(sftp->fstat_packet) {
LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL;
}
- if (sftp->unlink_packet) {
+ if(sftp->unlink_packet) {
LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL;
}
- if (sftp->rename_packet) {
+ if(sftp->rename_packet) {
LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL;
}
- if (sftp->fstatvfs_packet) {
+ if(sftp->fstatvfs_packet) {
LIBSSH2_FREE(session, sftp->fstatvfs_packet);
sftp->fstatvfs_packet = NULL;
}
- if (sftp->statvfs_packet) {
+ if(sftp->statvfs_packet) {
LIBSSH2_FREE(session, sftp->statvfs_packet);
sftp->statvfs_packet = NULL;
}
- if (sftp->mkdir_packet) {
+ if(sftp->mkdir_packet) {
LIBSSH2_FREE(session, sftp->mkdir_packet);
sftp->mkdir_packet = NULL;
}
- if (sftp->rmdir_packet) {
+ if(sftp->rmdir_packet) {
LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL;
}
- if (sftp->stat_packet) {
+ if(sftp->stat_packet) {
LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL;
}
- if (sftp->symlink_packet) {
+ if(sftp->symlink_packet) {
LIBSSH2_FREE(session, sftp->symlink_packet);
sftp->symlink_packet = NULL;
}
- if (sftp->fsync_packet) {
+ if(sftp->fsync_packet) {
LIBSSH2_FREE(session, sftp->fsync_packet);
sftp->fsync_packet = NULL;
}
@@ -1103,16 +1115,17 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
ssize_t rc;
int open_file = (open_type == LIBSSH2_SFTP_OPENFILE)?1:0;
- if (sftp->open_state == libssh2_NB_state_idle) {
+ if(sftp->open_state == libssh2_NB_state_idle) {
/* packet_len(4) + packet_type(1) + request_id(4) + filename_len(4) +
flags(4) */
sftp->open_packet_len = filename_len + 13 +
- (open_file? (4 + sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0);
+ (open_file? (4 +
+ sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS)) : 0);
/* surprise! this starts out with nothing sent */
sftp->open_packet_sent = 0;
s = sftp->open_packet = LIBSSH2_ALLOC(session, sftp->open_packet_len);
- if (!sftp->open_packet) {
+ if(!sftp->open_packet) {
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_OPEN or "
"FXP_OPENDIR packet");
@@ -1129,7 +1142,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
_libssh2_store_u32(&s, sftp->open_request_id);
_libssh2_store_str(&s, filename, filename_len);
- if (open_file) {
+ if(open_file) {
_libssh2_store_u32(&s, flags);
s += sftp_attr2bin(s, &attrs);
}
@@ -1140,14 +1153,15 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
sftp->open_state = libssh2_NB_state_created;
}
- if (sftp->open_state == libssh2_NB_state_created) {
+ if(sftp->open_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->open_packet+
sftp->open_packet_sent,
sftp->open_packet_len -
sftp->open_packet_sent);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
- "Would block sending FXP_OPEN or FXP_OPENDIR command");
+ "Would block sending FXP_OPEN or "
+ "FXP_OPENDIR command");
return NULL;
}
else if(rc < 0) {
@@ -1170,7 +1184,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
}
}
- if (sftp->open_state == libssh2_NB_state_sent) {
+ if(sftp->open_state == libssh2_NB_state_sent) {
size_t data_len;
unsigned char *data;
static const unsigned char fopen_responses[2] =
@@ -1178,13 +1192,13 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
rc = sftp_packet_requirev(sftp, 2, fopen_responses,
sftp->open_request_id, &data,
&data_len, 1);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for status message");
return NULL;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -1192,7 +1206,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
return NULL;
}
sftp->open_state = libssh2_NB_state_idle;
- if (rc) {
+ if(rc) {
_libssh2_error(session, rc, "Timeout waiting for status message");
return NULL;
}
@@ -1201,7 +1215,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
a fine response while STATUS means error. It seems though that at
times we get an SSH_FX_OK back in a STATUS, followed the "real"
HANDLE so we need to properly deal with that. */
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
int badness = 1;
if(data_len < 9) {
@@ -1214,7 +1228,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
sftp->last_errno = _libssh2_ntohu32(data + 5);
if(LIBSSH2_FX_OK == sftp->last_errno) {
- _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got HANDLE FXOK!");
+ _libssh2_debug(session, LIBSSH2_TRACE_SFTP,
+ "got HANDLE FXOK!");
LIBSSH2_FREE(session, data);
@@ -1227,8 +1242,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
sftp->open_state = libssh2_NB_state_sent;
return NULL;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -1243,7 +1258,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
if(badness) {
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Failed opening remote file");
- _libssh2_debug(session, LIBSSH2_TRACE_SFTP, "got FXP_STATUS %d",
+ _libssh2_debug(session, LIBSSH2_TRACE_SFTP,
+ "got FXP_STATUS %d",
sftp->last_errno);
LIBSSH2_FREE(session, data);
return NULL;
@@ -1258,7 +1274,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
}
fp = LIBSSH2_CALLOC(session, sizeof(LIBSSH2_SFTP_HANDLE));
- if (!fp) {
+ if(!fp) {
_libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate new SFTP handle structure");
LIBSSH2_FREE(session, data);
@@ -1268,7 +1284,7 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename,
LIBSSH2_SFTP_HANDLE_DIR;
fp->handle_len = _libssh2_ntohu32(data + 5);
- if (fp->handle_len > SFTP_HANDLE_MAXLEN)
+ if(fp->handle_len > SFTP_HANDLE_MAXLEN)
/* SFTP doesn't allow handles longer than 256 characters */
fp->handle_len = SFTP_HANDLE_MAXLEN;
@@ -1364,7 +1380,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
and second phases on the next call and resume sending.
*/
- switch (sftp->read_state) {
+ switch(sftp->read_state) {
case libssh2_NB_state_idle:
/* Some data may already have been read from the server in the
@@ -1388,9 +1404,10 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
return copy;
}
- if (filep->eof) {
+ if(filep->eof) {
return 0;
- } else {
+ }
+ else {
/* We allow a number of bytes being requested at any given time
without having been acked - until we reach EOF. */
@@ -1441,7 +1458,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
at next call */
assert(rc != LIBSSH2_ERROR_EAGAIN || !filep->data_left);
assert(rc != LIBSSH2_ERROR_EAGAIN || !filep->eof);
- if (rc)
+ if(rc)
return rc;
}
}
@@ -1455,14 +1472,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
uint32_t request_id;
uint32_t size = count;
- if (size < buffer_size)
+ if(size < buffer_size)
size = buffer_size;
- if (size > MAX_SFTP_READ_SIZE)
+ if(size > MAX_SFTP_READ_SIZE)
size = MAX_SFTP_READ_SIZE;
chunk = LIBSSH2_ALLOC(session, packet_len +
sizeof(struct sftp_pipeline_chunk));
- if (!chunk)
+ if(!chunk)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"malloc fail for FXP_WRITE");
@@ -1485,13 +1502,13 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* add this new entry LAST in the list */
_libssh2_list_add(&handle->packet_list, &chunk->node);
- count -= MIN(size,count); /* deduct the size we used, as we might
- * have to create more packets */
+ count -= MIN(size, count); /* deduct the size we used, as we might
+ * have to create more packets */
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"read request id %d sent (offset: %d, size: %d)",
request_id, (int)chunk->offset, (int)chunk->len);
}
-
+ /* FALL-THROUGH */
case libssh2_NB_state_sent:
sftp->read_state = libssh2_NB_state_idle;
@@ -1519,9 +1536,10 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* We still have data left to send for this chunk.
* If there is at least one completely sent chunk,
* we can get out of this loop and start reading. */
- if (chunk != _libssh2_list_first(&handle->packet_list)) {
+ if(chunk != _libssh2_list_first(&handle->packet_list)) {
break;
- } else {
+ }
+ else {
continue;
}
}
@@ -1530,6 +1548,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* move on to the next chunk with data to send */
chunk = _libssh2_list_next(&chunk->node);
}
+ /* FALL-THROUGH */
case libssh2_NB_state_sent2:
@@ -1551,9 +1570,10 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
if(chunk->lefttosend) {
/* if the chunk still has data left to send, we shouldn't wait
for an ACK for it just yet */
- if (bytes_in_buffer > 0) {
+ if(bytes_in_buffer > 0) {
return bytes_in_buffer;
- } else {
+ }
+ else {
/* we should never reach this point */
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"sftp_read() internal error");
@@ -1562,14 +1582,14 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
rc = sftp_packet_requirev(sftp, 2, read_responses,
chunk->request_id, &data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer != 0) {
+ if(rc == LIBSSH2_ERROR_EAGAIN && bytes_in_buffer != 0) {
/* do not return EAGAIN if we have already
* written data into the buffer */
return bytes_in_buffer;
}
- if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -1585,7 +1605,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
* FX_EOF when we reach the end of the file.
*/
- switch (data[0]) {
+ switch(data[0]) {
case SSH_FXP_STATUS:
/* remove the chunk we just processed */
@@ -1599,7 +1619,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
rc32 = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (rc32 == LIBSSH2_FX_EOF) {
+ if(rc32 == LIBSSH2_FX_EOF) {
filep->eof = TRUE;
return bytes_in_buffer;
}
@@ -1611,7 +1631,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
break;
case SSH_FXP_DATA:
- if (chunk->offset != filep->offset) {
+ if(chunk->offset != filep->offset) {
/* This could happen if the server returns less bytes than
requested, which shouldn't happen for normal files. See:
https://tools.ietf.org/html/draft-ietf-secsh-filexfer-02
@@ -1622,7 +1642,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
rc32 = _libssh2_ntohu32(data + 5);
- if (rc32 > (data_len - 9))
+ if(rc32 > (data_len - 9))
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol badness");
@@ -1676,9 +1696,10 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
/* check if we have space left in the buffer
* and either continue to the next chunk or stop
*/
- if (bytes_in_buffer < buffer_size) {
+ if(bytes_in_buffer < buffer_size) {
chunk = next;
- } else {
+ }
+ else {
chunk = NULL;
}
@@ -1690,7 +1711,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
}
}
- if (bytes_in_buffer > 0)
+ if(bytes_in_buffer > 0)
return bytes_in_buffer;
break;
@@ -1739,8 +1760,8 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
SSH_FXP_NAME, SSH_FXP_STATUS };
ssize_t retcode;
- if (sftp->readdir_state == libssh2_NB_state_idle) {
- if (handle->u.dir.names_left) {
+ if(sftp->readdir_state == libssh2_NB_state_idle) {
+ if(handle->u.dir.names_left) {
/*
* A prior request returned more than one directory entry,
* feed it back from the buffer
@@ -1750,29 +1771,53 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
size_t real_filename_len;
size_t filename_len;
size_t longentry_len;
-
- s = (unsigned char *) handle->u.dir.next_name;
- real_filename_len = _libssh2_ntohu32(s);
-
- s += 4;
+ size_t names_packet_len = handle->u.dir.names_packet_len;
+ int attr_len = 0;
+
+ if(names_packet_len >= 4) {
+ s = (unsigned char *) handle->u.dir.next_name;
+ real_filename_len = _libssh2_ntohu32(s);
+ s += 4;
+ names_packet_len -= 4;
+ }
+ else {
+ filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto end;
+ }
filename_len = real_filename_len;
- if (filename_len >= buffer_maxlen) {
+ if(filename_len >= buffer_maxlen) {
filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
goto end;
}
- memcpy(buffer, s, filename_len);
- buffer[filename_len] = '\0'; /* zero terminate */
- s += real_filename_len;
+ if(buffer_maxlen >= filename_len && names_packet_len >=
+ filename_len) {
+ memcpy(buffer, s, filename_len);
+ buffer[filename_len] = '\0'; /* zero terminate */
+ s += real_filename_len;
+ names_packet_len -= real_filename_len;
+ }
+ else {
+ filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto end;
+ }
- real_longentry_len = _libssh2_ntohu32(s);
- s += 4;
+ if(names_packet_len >= 4) {
+ real_longentry_len = _libssh2_ntohu32(s);
+ s += 4;
+ names_packet_len -= 4;
+ }
+ else {
+ filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto end;
+ }
- if (longentry && (longentry_maxlen>1)) {
+ if(longentry && (longentry_maxlen>1)) {
longentry_len = real_longentry_len;
- if (longentry_len >= longentry_maxlen) {
+ if(longentry_len >= longentry_maxlen ||
+ longentry_len > names_packet_len) {
filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
goto end;
}
@@ -1780,17 +1825,36 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
memcpy(longentry, s, longentry_len);
longentry[longentry_len] = '\0'; /* zero terminate */
}
- s += real_longentry_len;
- if (attrs)
+ if(real_longentry_len <= names_packet_len) {
+ s += real_longentry_len;
+ names_packet_len -= real_longentry_len;
+ }
+ else {
+ filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto end;
+ }
+
+ if(attrs)
memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
- s += sftp_bin2attr(attrs ? attrs : &attrs_dummy, s, 32);
+ attr_len = sftp_bin2attr(attrs ? attrs : &attrs_dummy, s,
+ names_packet_len);
+
+ if(attr_len >= 0) {
+ s += attr_len;
+ names_packet_len -= attr_len;
+ }
+ else {
+ filename_len = (size_t)LIBSSH2_ERROR_BUFFER_TOO_SMALL;
+ goto end;
+ }
handle->u.dir.next_name = (char *) s;
+ handle->u.dir.names_packet_len = names_packet_len;
end:
- if ((--handle->u.dir.names_left) == 0)
+ if((--handle->u.dir.names_left) == 0)
LIBSSH2_FREE(session, handle->u.dir.names_packet);
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
@@ -1802,7 +1866,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
/* Request another entry(entries?) */
s = sftp->readdir_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->readdir_packet)
+ if(!sftp->readdir_packet)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"FXP_READDIR packet");
@@ -1816,15 +1880,15 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
sftp->readdir_state = libssh2_NB_state_created;
}
- if (sftp->readdir_state == libssh2_NB_state_created) {
+ if(sftp->readdir_state == libssh2_NB_state_created) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Reading entries from directory handle");
retcode = _libssh2_channel_write(channel, 0, sftp->readdir_packet,
packet_len);
- if (retcode == LIBSSH2_ERROR_EAGAIN) {
+ if(retcode == LIBSSH2_ERROR_EAGAIN) {
return retcode;
}
- else if ((ssize_t)packet_len != retcode) {
+ else if((ssize_t)packet_len != retcode) {
LIBSSH2_FREE(session, sftp->readdir_packet);
sftp->readdir_packet = NULL;
sftp->readdir_state = libssh2_NB_state_idle;
@@ -1841,25 +1905,25 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
retcode = sftp_packet_requirev(sftp, 2, read_responses,
sftp->readdir_request_id, &data,
&data_len, 9);
- if (retcode == LIBSSH2_ERROR_EAGAIN)
+ if(retcode == LIBSSH2_ERROR_EAGAIN)
return retcode;
- else if (retcode == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(retcode == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
- return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
- "Status message too short");
+ return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
+ "Status message too short");
}
- else if (retcode) {
+ else if(retcode) {
sftp->readdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, retcode,
"Timeout waiting for status message");
}
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_EOF) {
+ if(retcode == LIBSSH2_FX_EOF) {
sftp->readdir_state = libssh2_NB_state_idle;
return 0;
}
@@ -1876,7 +1940,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
num_names = _libssh2_ntohu32(data + 5);
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%lu entries returned",
num_names);
- if (!num_names) {
+ if(!num_names) {
LIBSSH2_FREE(session, data);
return 0;
}
@@ -1884,6 +1948,7 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer,
handle->u.dir.names_left = num_names;
handle->u.dir.names_packet = data;
handle->u.dir.next_name = (char *) data + 9;
+ handle->u.dir.names_packet_len = data_len - 9;
/* use the name popping mechanism from the start of the function */
return sftp_readdir(handle, buffer, buffer_maxlen, longentry,
@@ -1967,14 +2032,15 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
default:
case libssh2_NB_state_idle:
- /* Number of bytes sent off that haven't been acked and therefor we
+ /* Number of bytes sent off that haven't been acked and therefore we
will get passed in here again.
Also, add up the number of bytes that actually already have been
acked but we haven't been able to return as such yet, so we will
get that data as well passed in here again.
*/
- already = (size_t) (handle->u.file.offset_sent - handle->u.file.offset)+
+ already = (size_t) (handle->u.file.offset_sent -
+ handle->u.file.offset)+
handle->u.file.acked;
if(count >= already) {
@@ -1999,7 +2065,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
chunk = LIBSSH2_ALLOC(session, packet_len +
sizeof(struct sftp_pipeline_chunk));
- if (!chunk)
+ if(!chunk)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"malloc fail for FXP_WRITE");
@@ -2027,8 +2093,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
to create more packets */
}
- /* move through the WRITE packets that haven't been sent and send as many
- as possible - remember that we don't block */
+ /* move through the WRITE packets that haven't been sent and send as
+ many as possible - remember that we don't block */
chunk = _libssh2_list_first(&handle->packet_list);
while(chunk) {
@@ -2076,15 +2142,15 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
/* we check the packets in order */
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
chunk->request_id, &data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"FXP write packet too short");
}
- else if (rc < 0) {
- if (rc == LIBSSH2_ERROR_EAGAIN)
+ else if(rc < 0) {
+ if(rc == LIBSSH2_ERROR_EAGAIN)
sftp->write_state = libssh2_NB_state_sent;
return rc;
}
@@ -2093,7 +2159,7 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
LIBSSH2_FREE(session, data);
sftp->last_errno = retcode;
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
acked += chunk->len; /* number of payload data that was acked
here */
@@ -2113,7 +2179,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
/* since we return error now, the application will not get any
outstanding data acked, so we need to rewind the offset to
- where the application knows it has reached with acked data */
+ where the application knows it has reached with acked
+ data */
handle->u.file.offset -= handle->u.file.acked;
/* then reset the offset_sent to be the same as the offset */
@@ -2123,8 +2190,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer,
ack after an error */
handle->u.file.acked = 0;
- /* the server returned an error for that written chunk, propagate
- this back to our parent function */
+ /* the server returned an error for that written chunk,
+ propagate this back to our parent function */
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"FXP write failed");
}
@@ -2183,11 +2250,11 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
ssize_t rc;
uint32_t retcode;
- if (sftp->fsync_state == libssh2_NB_state_idle) {
+ if(sftp->fsync_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Issuing fsync command");
s = packet = LIBSSH2_ALLOC(session, packet_len);
- if (!packet) {
+ if(!packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_EXTENDED "
"packet");
@@ -2201,13 +2268,14 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
_libssh2_store_str(&s, handle->handle, handle->handle_len);
sftp->fsync_state = libssh2_NB_state_created;
- } else {
+ }
+ else {
packet = sftp->fsync_packet;
}
- if (sftp->fsync_state == libssh2_NB_state_created) {
+ if(sftp->fsync_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, packet, packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN ||
+ if(rc == LIBSSH2_ERROR_EAGAIN ||
(0 <= rc && rc < (ssize_t)packet_len)) {
sftp->fsync_packet = packet;
return LIBSSH2_ERROR_EAGAIN;
@@ -2216,7 +2284,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
LIBSSH2_FREE(session, packet);
sftp->fsync_packet = NULL;
- if (rc < 0) {
+ if(rc < 0) {
sftp->fsync_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
@@ -2226,17 +2294,17 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
sftp->fsync_request_id, &data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP fsync packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->fsync_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY");
@@ -2247,7 +2315,7 @@ static int sftp_fsync(LIBSSH2_SFTP_HANDLE *handle)
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode != LIBSSH2_FX_OK) {
+ if(retcode != LIBSSH2_FX_OK) {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"fsync failed");
@@ -2291,11 +2359,11 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
{ SSH_FXP_ATTRS, SSH_FXP_STATUS };
ssize_t rc;
- if (sftp->fstat_state == libssh2_NB_state_idle) {
+ if(sftp->fstat_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Issuing %s command",
setstat ? "set-stat" : "stat");
s = sftp->fstat_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->fstat_packet) {
+ if(!sftp->fstat_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"FSTAT/FSETSTAT packet");
@@ -2307,20 +2375,20 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
_libssh2_store_u32(&s, sftp->fstat_request_id);
_libssh2_store_str(&s, handle->handle, handle->handle_len);
- if (setstat) {
+ if(setstat) {
s += sftp_attr2bin(s, attrs);
}
sftp->fstat_state = libssh2_NB_state_created;
}
- if (sftp->fstat_state == libssh2_NB_state_created) {
+ if(sftp->fstat_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->fstat_packet,
packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if ((ssize_t)packet_len != rc) {
+ else if((ssize_t)packet_len != rc) {
LIBSSH2_FREE(session, sftp->fstat_packet);
sftp->fstat_packet = NULL;
sftp->fstat_state = libssh2_NB_state_idle;
@@ -2337,16 +2405,16 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
rc = sftp_packet_requirev(sftp, 2, fstat_responses,
sftp->fstat_request_id, &data,
&data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN)
+ if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP fstat packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->fstat_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Timeout waiting for status message");
@@ -2354,21 +2422,22 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle,
sftp->fstat_state = libssh2_NB_state_idle;
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
uint32_t retcode;
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
return 0;
- } else {
+ }
+ else {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
}
}
- if (sftp_bin2attr(attrs, data + 5, data_len - 5) < 0) {
+ if(sftp_bin2attr(attrs, data + 5, data_len - 5) < 0) {
LIBSSH2_FREE(session, data);
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Attributes too short in SFTP fstat");
@@ -2411,7 +2480,7 @@ libssh2_sftp_seek64(LIBSSH2_SFTP_HANDLE *handle, libssh2_uint64_t offset)
sftp_packetlist_flush(handle);
/* free the left received buffered data */
- if (handle->u.file.data_left) {
+ if(handle->u.file.data_left) {
LIBSSH2_FREE(handle->sftp->channel->session, handle->u.file.data);
handle->u.file.data_left = handle->u.file.data_len = 0;
handle->u.file.data = NULL;
@@ -2512,15 +2581,16 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
unsigned char *s, *data = NULL;
int rc = 0;
- if (handle->close_state == libssh2_NB_state_idle) {
+ if(handle->close_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Closing handle");
s = handle->close_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!handle->close_packet) {
+ if(!handle->close_packet) {
handle->close_state = libssh2_NB_state_idle;
rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_CLOSE "
"packet");
- } else {
+ }
+ else {
_libssh2_store_u32(&s, packet_len - 4);
*(s++) = SSH_FXP_CLOSE;
@@ -2531,38 +2601,40 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
}
}
- if (handle->close_state == libssh2_NB_state_created) {
+ if(handle->close_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, handle->close_packet,
packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
- } else if ((ssize_t)packet_len != rc) {
+ }
+ else if((ssize_t)packet_len != rc) {
handle->close_state = libssh2_NB_state_idle;
rc = _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_CLOSE command");
- } else
+ }
+ else
handle->close_state = libssh2_NB_state_sent;
LIBSSH2_FREE(session, handle->close_packet);
handle->close_packet = NULL;
}
- if (handle->close_state == libssh2_NB_state_sent) {
+ if(handle->close_state == libssh2_NB_state_sent) {
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
handle->close_request_id, &data,
&data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
data = NULL;
_libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Packet too short in FXP_CLOSE command");
}
- else if (rc) {
+ else if(rc) {
_libssh2_error(session, rc,
"Error waiting for status message");
}
@@ -2575,11 +2647,12 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
happened for which we should have set an error code */
assert(rc);
- } else {
+ }
+ else {
int retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode != LIBSSH2_FX_OK) {
+ if(retcode != LIBSSH2_FX_OK) {
sftp->last_errno = retcode;
handle->close_state = libssh2_NB_state_idle;
rc = _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -2590,11 +2663,11 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle)
/* remove this handle from the parent's list */
_libssh2_list_remove(&handle->node);
- if ((handle->handle_type == LIBSSH2_SFTP_HANDLE_DIR)
- && handle->u.dir.names_left) {
- LIBSSH2_FREE(session, handle->u.dir.names_packet);
+ if(handle->handle_type == LIBSSH2_SFTP_HANDLE_DIR) {
+ if(handle->u.dir.names_left)
+ LIBSSH2_FREE(session, handle->u.dir.names_packet);
}
- else {
+ else if(handle->handle_type == LIBSSH2_SFTP_HANDLE_FILE) {
if(handle->u.file.data)
LIBSSH2_FREE(session, handle->u.file.data);
}
@@ -2639,10 +2712,10 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
unsigned char *s, *data;
int rc;
- if (sftp->unlink_state == libssh2_NB_state_idle) {
+ if(sftp->unlink_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Unlinking %s", filename);
s = sftp->unlink_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->unlink_packet) {
+ if(!sftp->unlink_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_REMOVE "
"packet");
@@ -2656,12 +2729,13 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
sftp->unlink_state = libssh2_NB_state_created;
}
- if (sftp->unlink_state == libssh2_NB_state_created) {
+ if(sftp->unlink_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->unlink_packet,
packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
- } else if ((ssize_t)packet_len != rc) {
+ }
+ else if((ssize_t)packet_len != rc) {
LIBSSH2_FREE(session, sftp->unlink_packet);
sftp->unlink_packet = NULL;
sftp->unlink_state = libssh2_NB_state_idle;
@@ -2677,17 +2751,17 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
sftp->unlink_request_id, &data,
&data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP unlink packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->unlink_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP STATUS");
@@ -2698,9 +2772,10 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename,
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
return 0;
- } else {
+ }
+ else {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
@@ -2744,17 +2819,17 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
unsigned char *data;
ssize_t rc;
- if (sftp->version < 2) {
+ if(sftp->version < 2) {
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support RENAME");
}
- if (sftp->rename_state == libssh2_NB_state_idle) {
+ if(sftp->rename_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Renaming %s to %s",
source_filename, dest_filename);
sftp->rename_s = sftp->rename_packet =
LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->rename_packet) {
+ if(!sftp->rename_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RENAME "
"packet");
@@ -2768,18 +2843,19 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
source_filename_len);
_libssh2_store_str(&sftp->rename_s, dest_filename, dest_filename_len);
- if (sftp->version >= 5)
+ if(sftp->version >= 5)
_libssh2_store_u32(&sftp->rename_s, flags);
sftp->rename_state = libssh2_NB_state_created;
}
- if (sftp->rename_state == libssh2_NB_state_created) {
+ if(sftp->rename_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->rename_packet,
sftp->rename_s - sftp->rename_packet);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
- } else if ((ssize_t)packet_len != rc) {
+ }
+ else if((ssize_t)packet_len != rc) {
LIBSSH2_FREE(session, sftp->rename_packet);
sftp->rename_packet = NULL;
sftp->rename_state = libssh2_NB_state_idle;
@@ -2795,17 +2871,17 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
sftp->rename_request_id, &data,
&data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP rename packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->rename_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP STATUS");
@@ -2820,7 +2896,7 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename,
/* now convert the SFTP error code to libssh2 return code or error
message */
- switch (retcode) {
+ switch(retcode) {
case LIBSSH2_FX_OK:
retcode = LIBSSH2_ERROR_NONE;
break;
@@ -2884,11 +2960,11 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
static const unsigned char responses[2] =
{ SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS };
- if (sftp->fstatvfs_state == libssh2_NB_state_idle) {
+ if(sftp->fstatvfs_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Getting file system statistics");
s = packet = LIBSSH2_ALLOC(session, packet_len);
- if (!packet) {
+ if(!packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_EXTENDED "
"packet");
@@ -2907,9 +2983,9 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
packet = sftp->fstatvfs_packet;
}
- if (sftp->fstatvfs_state == libssh2_NB_state_created) {
+ if(sftp->fstatvfs_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, packet, packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN ||
+ if(rc == LIBSSH2_ERROR_EAGAIN ||
(0 <= rc && rc < (ssize_t)packet_len)) {
sftp->fstatvfs_packet = packet;
return LIBSSH2_ERROR_EAGAIN;
@@ -2918,7 +2994,7 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
LIBSSH2_FREE(session, packet);
sftp->fstatvfs_packet = NULL;
- if (rc < 0) {
+ if(rc < 0) {
sftp->fstatvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
@@ -2929,23 +3005,23 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
rc = sftp_packet_requirev(sftp, 2, responses, sftp->fstatvfs_request_id,
&data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP rename packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->fstatvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY");
}
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
int retcode = _libssh2_ntohu32(data + 5);
sftp->fstatvfs_state = libssh2_NB_state_idle;
LIBSSH2_FREE(session, data);
@@ -2954,7 +3030,7 @@ static int sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
"SFTP Protocol Error");
}
- if (data_len < 93) {
+ if(data_len < 93) {
LIBSSH2_FREE(session, data);
sftp->fstatvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -2994,7 +3070,8 @@ libssh2_sftp_fstatvfs(LIBSSH2_SFTP_HANDLE *handle, LIBSSH2_SFTP_STATVFS *st)
int rc;
if(!handle || !st)
return LIBSSH2_ERROR_BAD_USE;
- BLOCK_ADJUST(rc, handle->sftp->channel->session, sftp_fstatvfs(handle, st));
+ BLOCK_ADJUST(rc, handle->sftp->channel->session,
+ sftp_fstatvfs(handle, st));
return rc;
}
@@ -3019,11 +3096,11 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
static const unsigned char responses[2] =
{ SSH_FXP_EXTENDED_REPLY, SSH_FXP_STATUS };
- if (sftp->statvfs_state == libssh2_NB_state_idle) {
+ if(sftp->statvfs_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Getting file system statistics of %s", path);
s = packet = LIBSSH2_ALLOC(session, packet_len);
- if (!packet) {
+ if(!packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_EXTENDED "
"packet");
@@ -3042,9 +3119,9 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
packet = sftp->statvfs_packet;
}
- if (sftp->statvfs_state == libssh2_NB_state_created) {
+ if(sftp->statvfs_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, packet, packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN ||
+ if(rc == LIBSSH2_ERROR_EAGAIN ||
(0 <= rc && rc < (ssize_t)packet_len)) {
sftp->statvfs_packet = packet;
return LIBSSH2_ERROR_EAGAIN;
@@ -3053,7 +3130,7 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_FREE(session, packet);
sftp->statvfs_packet = NULL;
- if (rc < 0) {
+ if(rc < 0) {
sftp->statvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"_libssh2_channel_write() failed");
@@ -3063,23 +3140,23 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
rc = sftp_packet_requirev(sftp, 2, responses, sftp->statvfs_request_id,
&data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP fstat packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->statvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP EXTENDED REPLY");
}
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
int retcode = _libssh2_ntohu32(data + 5);
sftp->statvfs_state = libssh2_NB_state_idle;
LIBSSH2_FREE(session, data);
@@ -3088,7 +3165,7 @@ static int sftp_statvfs(LIBSSH2_SFTP *sftp, const char *path,
"SFTP Protocol Error");
}
- if (data_len < 93) {
+ if(data_len < 93) {
LIBSSH2_FREE(session, data);
sftp->statvfs_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -3146,27 +3223,32 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
LIBSSH2_CHANNEL *channel = sftp->channel;
LIBSSH2_SESSION *session = channel->session;
LIBSSH2_SFTP_ATTRIBUTES attrs = {
- LIBSSH2_SFTP_ATTR_PERMISSIONS, 0, 0, 0, 0, 0, 0
+ 0, 0, 0, 0, 0, 0, 0
};
size_t data_len;
int retcode;
- /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */
- ssize_t packet_len = path_len + 13 +
- sftp_attrsize(LIBSSH2_SFTP_ATTR_PERMISSIONS);
+ ssize_t packet_len;
unsigned char *packet, *s, *data;
int rc;
- if (sftp->mkdir_state == libssh2_NB_state_idle) {
+ if(mode != LIBSSH2_SFTP_DEFAULT_MODE) {
+ /* Filetype in SFTP 3 and earlier */
+ attrs.flags = LIBSSH2_SFTP_ATTR_PERMISSIONS;
+ attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
+ }
+
+ /* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */
+ packet_len = path_len + 13 + sftp_attrsize(attrs.flags);
+
+ if(sftp->mkdir_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP,
"Creating directory %s with mode 0%lo", path, mode);
s = packet = LIBSSH2_ALLOC(session, packet_len);
- if (!packet) {
+ if(!packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR "
"packet");
}
- /* Filetype in SFTP 3 and earlier */
- attrs.permissions = mode | LIBSSH2_SFTP_ATTR_PFILETYPE_DIR;
_libssh2_store_u32(&s, packet_len - 4);
*(s++) = SSH_FXP_MKDIR;
@@ -3182,13 +3264,13 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
packet = sftp->mkdir_packet;
}
- if (sftp->mkdir_state == libssh2_NB_state_created) {
+ if(sftp->mkdir_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, packet, packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
sftp->mkdir_packet = packet;
return rc;
}
- if (packet_len != rc) {
+ if(packet_len != rc) {
LIBSSH2_FREE(session, packet);
sftp->mkdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
@@ -3201,17 +3283,17 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->mkdir_request_id,
&data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP mkdir packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->mkdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP STATUS");
@@ -3222,10 +3304,11 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path,
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "OK!");
return 0;
- } else {
+ }
+ else {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
@@ -3264,11 +3347,11 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
unsigned char *s, *data;
int rc;
- if (sftp->rmdir_state == libssh2_NB_state_idle) {
+ if(sftp->rmdir_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "Removing directory: %s",
path);
s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->rmdir_packet) {
+ if(!sftp->rmdir_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_RMDIR "
"packet");
@@ -3283,12 +3366,13 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
sftp->rmdir_state = libssh2_NB_state_created;
}
- if (sftp->rmdir_state == libssh2_NB_state_created) {
+ if(sftp->rmdir_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->rmdir_packet,
packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
- } else if (packet_len != rc) {
+ }
+ else if(packet_len != rc) {
LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL;
sftp->rmdir_state = libssh2_NB_state_idle;
@@ -3303,17 +3387,17 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
rc = sftp_packet_require(sftp, SSH_FXP_STATUS,
sftp->rmdir_request_id, &data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP rmdir packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->rmdir_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Error waiting for FXP STATUS");
@@ -3324,9 +3408,10 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path,
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
return 0;
- } else {
+ }
+ else {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
@@ -3368,13 +3453,13 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
{ SSH_FXP_ATTRS, SSH_FXP_STATUS };
int rc;
- if (sftp->stat_state == libssh2_NB_state_idle) {
+ if(sftp->stat_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_TRACE_SFTP, "%s %s",
(stat_type == LIBSSH2_SFTP_SETSTAT) ? "Set-statting" :
(stat_type ==
LIBSSH2_SFTP_LSTAT ? "LStatting" : "Statting"), path);
s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->stat_packet) {
+ if(!sftp->stat_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_*STAT "
"packet");
@@ -3382,7 +3467,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
_libssh2_store_u32(&s, packet_len - 4);
- switch (stat_type) {
+ switch(stat_type) {
case LIBSSH2_SFTP_SETSTAT:
*(s++) = SSH_FXP_SETSTAT;
break;
@@ -3399,17 +3484,18 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
_libssh2_store_u32(&s, sftp->stat_request_id);
_libssh2_store_str(&s, path, path_len);
- if (stat_type == LIBSSH2_SFTP_SETSTAT)
+ if(stat_type == LIBSSH2_SFTP_SETSTAT)
s += sftp_attr2bin(s, attrs);
sftp->stat_state = libssh2_NB_state_created;
}
- if (sftp->stat_state == libssh2_NB_state_created) {
+ if(sftp->stat_state == libssh2_NB_state_created) {
rc = _libssh2_channel_write(channel, 0, sftp->stat_packet, packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN) {
+ if(rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
- } else if (packet_len != rc) {
+ }
+ else if(packet_len != rc) {
LIBSSH2_FREE(session, sftp->stat_packet);
sftp->stat_packet = NULL;
sftp->stat_state = libssh2_NB_state_idle;
@@ -3424,16 +3510,16 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
rc = sftp_packet_requirev(sftp, 2, stat_responses,
sftp->stat_request_id, &data, &data_len, 9);
- if (rc == LIBSSH2_ERROR_EAGAIN)
+ if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
- else if (rc == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(rc == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP stat packet too short");
}
- else if (rc) {
+ else if(rc) {
sftp->stat_state = libssh2_NB_state_idle;
return _libssh2_error(session, rc,
"Timeout waiting for status message");
@@ -3441,14 +3527,16 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
sftp->stat_state = libssh2_NB_state_idle;
- if (data[0] == SSH_FXP_STATUS) {
+ if(data[0] == SSH_FXP_STATUS) {
int retcode;
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK) {
+ if(retcode == LIBSSH2_FX_OK) {
+ memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
return 0;
- } else {
+ }
+ else {
sftp->last_errno = retcode;
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP Protocol Error");
@@ -3456,7 +3544,7 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path,
}
memset(attrs, 0, sizeof(LIBSSH2_SFTP_ATTRIBUTES));
- if (sftp_bin2attr(attrs, data + 5, data_len - 5) < 0) {
+ if(sftp_bin2attr(attrs, data + 5, data_len - 5) < 0) {
LIBSSH2_FREE(session, data);
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Attributes too short in SFTP fstat");
@@ -3502,14 +3590,14 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
{ SSH_FXP_NAME, SSH_FXP_STATUS };
int retcode;
- if ((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) {
+ if((sftp->version < 3) && (link_type != LIBSSH2_SFTP_REALPATH)) {
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Server does not support SYMLINK or READLINK");
}
- if (sftp->symlink_state == libssh2_NB_state_idle) {
+ if(sftp->symlink_state == libssh2_NB_state_idle) {
s = sftp->symlink_packet = LIBSSH2_ALLOC(session, packet_len);
- if (!sftp->symlink_packet) {
+ if(!sftp->symlink_packet) {
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for "
"SYMLINK/READLINK/REALPATH packet");
@@ -3523,7 +3611,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
_libssh2_store_u32(&s, packet_len - 4);
- switch (link_type) {
+ switch(link_type) {
case LIBSSH2_SFTP_REALPATH:
*(s++) = SSH_FXP_REALPATH;
break;
@@ -3540,18 +3628,18 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
_libssh2_store_u32(&s, sftp->symlink_request_id);
_libssh2_store_str(&s, path, path_len);
- if (link_type == LIBSSH2_SFTP_SYMLINK)
+ if(link_type == LIBSSH2_SFTP_SYMLINK)
_libssh2_store_str(&s, target, target_len);
sftp->symlink_state = libssh2_NB_state_created;
}
- if (sftp->symlink_state == libssh2_NB_state_created) {
+ if(sftp->symlink_state == libssh2_NB_state_created) {
ssize_t rc = _libssh2_channel_write(channel, 0, sftp->symlink_packet,
packet_len);
- if (rc == LIBSSH2_ERROR_EAGAIN)
+ if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
- else if (packet_len != rc) {
+ else if(packet_len != rc) {
LIBSSH2_FREE(session, sftp->symlink_packet);
sftp->symlink_packet = NULL;
sftp->symlink_state = libssh2_NB_state_idle;
@@ -3567,16 +3655,16 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
retcode = sftp_packet_requirev(sftp, 2, link_responses,
sftp->symlink_request_id, &data,
&data_len, 9);
- if (retcode == LIBSSH2_ERROR_EAGAIN)
+ if(retcode == LIBSSH2_ERROR_EAGAIN)
return retcode;
- else if (retcode == LIBSSH2_ERROR_OUT_OF_BOUNDARY) {
- if (data_len > 0) {
+ else if(retcode == LIBSSH2_ERROR_BUFFER_TOO_SMALL) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"SFTP symlink packet too short");
}
- else if (retcode) {
+ else if(retcode) {
sftp->symlink_state = libssh2_NB_state_idle;
return _libssh2_error(session, retcode,
"Error waiting for status message");
@@ -3584,12 +3672,10 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
sftp->symlink_state = libssh2_NB_state_idle;
- if (data[0] == SSH_FXP_STATUS) {
- int retcode;
-
+ if(data[0] == SSH_FXP_STATUS) {
retcode = _libssh2_ntohu32(data + 5);
LIBSSH2_FREE(session, data);
- if (retcode == LIBSSH2_FX_OK)
+ if(retcode == LIBSSH2_FX_OK)
return LIBSSH2_ERROR_NONE;
else {
sftp->last_errno = retcode;
@@ -3598,15 +3684,15 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
}
}
- if (_libssh2_ntohu32(data + 5) < 1) {
+ if(_libssh2_ntohu32(data + 5) < 1) {
LIBSSH2_FREE(session, data);
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
"Invalid READLINK/REALPATH response, "
"no name entries");
}
- if (data_len < 13) {
- if (data_len > 0) {
+ if(data_len < 13) {
+ if(data_len > 0) {
LIBSSH2_FREE(session, data);
}
return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@@ -3615,7 +3701,7 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path,
/* this reads a u32 and stores it into a signed 32bit value */
link_len = _libssh2_ntohu32(data + 9);
- if (link_len < target_len) {
+ if(link_len < target_len) {
memcpy(target, data + 13, link_len);
target[link_len] = 0;
retcode = (int)link_len;
@@ -3662,7 +3748,7 @@ libssh2_sftp_last_error(LIBSSH2_SFTP *sftp)
LIBSSH2_API LIBSSH2_CHANNEL *
libssh2_sftp_get_channel(LIBSSH2_SFTP *sftp)
{
- if (!sftp)
+ if(!sftp)
return NULL;
return sftp->channel;