aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-03-01 19:59:06 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2010-03-01 20:00:02 +0100
commite8a1d135e21721426851312dc2a9180e5c38273f (patch)
tree0a7f6b98690b79a9c91a74025d94058d1ecaf4f0 /libssh
parentb707b5e2a477669181ca2ebca7395d28fb0e3087 (diff)
downloadlibssh-e8a1d135e21721426851312dc2a9180e5c38273f.tar.gz
libssh-e8a1d135e21721426851312dc2a9180e5c38273f.tar.xz
libssh-e8a1d135e21721426851312dc2a9180e5c38273f.zip
Fix a race condition bug in ssh_scp_close()
Conflicts: libssh/scp.c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/scp.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/libssh/scp.c b/libssh/scp.c
index a9bd1fdc..81c32908 100644
--- a/libssh/scp.c
+++ b/libssh/scp.c
@@ -26,7 +26,6 @@
#include "libssh/priv.h"
#include "libssh/scp.h"
-
/** @defgroup ssh_scp SSH-scp
* @brief SCP protocol over SSH functions
* @addtogroup ssh_scp
@@ -120,6 +119,8 @@ int ssh_scp_init(ssh_scp scp){
}
int ssh_scp_close(ssh_scp scp){
+ char buffer[128];
+ int err;
if(scp==NULL)
return SSH_ERROR;
if(scp->channel != NULL){
@@ -127,6 +128,15 @@ int ssh_scp_close(ssh_scp scp){
scp->state=SSH_SCP_ERROR;
return SSH_ERROR;
}
+ /* avoid situations where data are buffered and
+ * not yet stored on disk. This can happen if the close is sent
+ * before we got the EOF back
+ */
+ while(!channel_is_eof(scp->channel)){
+ err=channel_read(scp->channel,buffer,sizeof(buffer),0);
+ if(err==SSH_ERROR)
+ break;
+ }
if(channel_close(scp->channel) == SSH_ERROR){
scp->state=SSH_SCP_ERROR;
return SSH_ERROR;