aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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){