aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-27 11:49:41 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-27 11:49:41 +0000
commit52d20beb731bb00fd9770da04d21aeec04dfd9c9 (patch)
treeb79975aab3448447c9f3a20b2c68dcd91dc51431
parentf11630ab68b95fc64c0d3e7d1af9518ead22c853 (diff)
downloadlibssh-52d20beb731bb00fd9770da04d21aeec04dfd9c9.tar.gz
libssh-52d20beb731bb00fd9770da04d21aeec04dfd9c9.tar.xz
libssh-52d20beb731bb00fd9770da04d21aeec04dfd9c9.zip
Improve sftp_reply_names.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@626 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--libssh/sftpserver.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 4e1cebff..901ad862 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -332,22 +332,34 @@ int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
return 0;
}
-int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg){
- BUFFER *out=buffer_new();
- int r;
- buffer_add_u32(out,msg->id);
- buffer_add_u32(out,htonl(msg->attr_num));
- buffer_add_data(out,buffer_get(msg->attrbuf),
- buffer_get_len(msg->attrbuf));
- r=sftp_packet_write(msg->sftp,SSH_FXP_NAME,out);
+int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg) {
+ BUFFER *out;
+
+ out = buffer_new();
+ if (out == NULL) {
+ buffer_free(msg->attrbuf);
+ return -1;
+ }
+
+ if (buffer_add_u32(out, msg->id) < 0 ||
+ buffer_add_u32(out, htonl(msg->attr_num)) < 0 ||
+ buffer_add_data(out, buffer_get(msg->attrbuf),
+ buffer_get_len(msg->attrbuf)) < 0 ||
+ sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
buffer_free(out);
buffer_free(msg->attrbuf);
- msg->attr_num=0;
- msg->attrbuf=NULL;
- return r<0;
+ return -1;
+ }
+
+ buffer_free(out);
+ buffer_free(msg->attrbuf);
+
+ msg->attr_num = 0;
+ msg->attrbuf = NULL;
+
+ return 0;
}
-
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, char *message){
BUFFER *out=buffer_new();
int r;