aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/sftp.h3
-rw-r--r--libssh/sftpserver.c41
2 files changed, 31 insertions, 13 deletions
diff --git a/include/libssh/sftp.h b/include/libssh/sftp.h
index c7e6a7c1..a54ec495 100644
--- a/include/libssh/sftp.h
+++ b/include/libssh/sftp.h
@@ -647,7 +647,8 @@ SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, BUFFER *buf,int expectna
SFTP_CLIENT_MESSAGE *sftp_get_client_message(SFTP_SESSION *sftp);
void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg);
-int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, char *name, SFTP_ATTRIBUTES *attr);
+int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name,
+ SFTP_ATTRIBUTES *attr);
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle);
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info);
int sftp_reply_attr(SFTP_CLIENT_MESSAGE *msg, SFTP_ATTRIBUTES *attr);
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 51c21176..07f432a9 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -224,19 +224,36 @@ void sftp_client_message_free(SFTP_CLIENT_MESSAGE *msg) {
SAFE_FREE(msg);
}
-int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, char *name, SFTP_ATTRIBUTES *attr){
- BUFFER *out=buffer_new();
- STRING *file=string_from_char(name);
- int r;
- buffer_add_u32(out,msg->id);
- buffer_add_u32(out,htonl(1));
- buffer_add_ssh_string(out,file);
- buffer_add_ssh_string(out,file); /* the protocol is broken here between 3 & 4 */
- free(file);
- buffer_add_attributes(out,attr);
- r=sftp_packet_write(msg->sftp,SSH_FXP_NAME,out);
+int sftp_reply_name(SFTP_CLIENT_MESSAGE *msg, const char *name,
+ SFTP_ATTRIBUTES *attr) {
+ BUFFER *out;
+ STRING *file;
+
+ out = buffer_new();
+ if (out == NULL) {
+ return -1;
+ }
+
+ file = string_from_char(name);
+ if (file == NULL) {
buffer_free(out);
- return r<0;
+ return -1;
+ }
+
+ if (buffer_add_u32(out, msg->id) < 0 ||
+ buffer_add_u32(out, htonl(1)) < 0 ||
+ buffer_add_ssh_string(out, file) < 0 ||
+ buffer_add_ssh_string(out, file) < 0 || /* The protocol is broken here between 3 & 4 */
+ buffer_add_attributes(out, attr) < 0 ||
+ sftp_packet_write(msg->sftp, SSH_FXP_NAME, out) < 0) {
+ buffer_free(out);
+ string_free(file);
+ return -1;
+ }
+ buffer_free(out);
+ string_free(file);
+
+ return 0;
}
int sftp_reply_handle(SFTP_CLIENT_MESSAGE *msg, STRING *handle){