aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-03-01 19:51:07 +0100
committerAris Adamantiadis <aris@0xbadc0de.be>2010-03-01 20:00:29 +0100
commit370d072ebaa7471ee1cac026f1b8e22d07f50b28 (patch)
tree36df51242eb098caf643adcca28e83adc2829114
parent56dfa69fc97077779591374f2c6faa1b0a5c3e03 (diff)
downloadlibssh-370d072ebaa7471ee1cac026f1b8e22d07f50b28.tar.gz
libssh-370d072ebaa7471ee1cac026f1b8e22d07f50b28.tar.xz
libssh-370d072ebaa7471ee1cac026f1b8e22d07f50b28.zip
Fix a race condition bug in ssh_scp_close()
-rw-r--r--libssh/scp.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/libssh/scp.c b/libssh/scp.c
index 0086b6fa..ac016b36 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
@@ -118,11 +117,22 @@ int ssh_scp_init(ssh_scp scp){
}
int ssh_scp_close(ssh_scp scp){
+ char buffer[128];
+ int err;
if(scp->channel != NULL){
if(channel_send_eof(scp->channel) == SSH_ERROR){
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;