aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-27 11:46:41 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-27 11:46:41 +0000
commitf11630ab68b95fc64c0d3e7d1af9518ead22c853 (patch)
tree028f1337759fcfaeee14e07f1e0bb2d5aa43984a
parentf32e307899f96bf67abcea7a9f70df51852d9eae (diff)
downloadlibssh-f11630ab68b95fc64c0d3e7d1af9518ead22c853.tar.gz
libssh-f11630ab68b95fc64c0d3e7d1af9518ead22c853.tar.xz
libssh-f11630ab68b95fc64c0d3e7d1af9518ead22c853.zip
Improve sftp_reply_names_add.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@625 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r--include/libssh/sftp.h4
-rw-r--r--libssh/sftpserver.c49
2 files changed, 38 insertions, 15 deletions
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index a54ec495..486165d8 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -654,8 +654,8 @@ STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info);
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr);
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle);
int sftp_reply_status(SFTP_CLIENT_MESSAGE *msg, u32 status, char *message);
-int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, char *file, char *longname,
- SFTP_ATTRIBUTES *attr);
+int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
+ const char *longname, SFTP_ATTRIBUTES *attr);
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg);
int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, void *data, int len);
void sftp_handle_remove(SFTP_SESSION *sftp, void *handle);
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 08b214c3..4e1cebff 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -294,19 +294,42 @@ int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr) {
return 0;
}
-int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, char *file, char *longname,
- SFTP_ATTRIBUTES *attr){
- STRING *name=string_from_char(file);
- if(!msg->attrbuf)
- msg->attrbuf=buffer_new();
- buffer_add_ssh_string(msg->attrbuf,name);
- free(name);
- name=string_from_char(longname);
- buffer_add_ssh_string(msg->attrbuf,name);
- free(name);
- buffer_add_attributes(msg->attrbuf,attr);
- msg->attr_num++;
- return 0;
+int sftp_reply_names_add(SFTP_CLIENT_MESSAGE *msg, const char *file,
+ const char *longname, SFTP_ATTRIBUTES *attr) {
+ STRING *name;
+
+ name = string_from_char(file);
+ if (name == NULL) {
+ return -1;
+ }
+
+ if (msg->attrbuf == NULL) {
+ msg->attrbuf = buffer_new();
+ if (msg->attrbuf == NULL) {
+ string_free(name);
+ return -1;
+ }
+ }
+
+ if (buffer_add_ssh_string(msg->attrbuf, name) < 0) {
+ string_free(name);
+ return -1;
+ }
+
+ string_free(name);
+ name = string_from_char(longname);
+ if (name == NULL) {
+ return -1;
+ }
+ if (buffer_add_ssh_string(msg->attrbuf,name) < 0 ||
+ buffer_add_attributes(msg->attrbuf,attr) < 0) {
+ string_free(name);
+ return -1;
+ }
+ string_free(name);
+ msg->attr_num++;
+
+ return 0;
}
int sftp_reply_names(SFTP_CLIENT_MESSAGE *msg){