From 8ea9b14a806f63dfa123838d2e82bed70340ab02 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 24 Feb 2020 17:55:06 -0800 Subject: [PATCH] GUACAMOLE-818: Break SFTP directory JSON at blob boundaries. Do not skip entries. The intent of the previous version of the SFTP directory listing code was to break the JSON transfer at blob boundaries, waiting for an ack before sending the next blob, however the ordering of the "blob_written" and directory read checks could result in a directory entry being skipped at the boundary of each blob. The proper order would be to check the "blob_written" flag first, however the "blob_written" flag is unnecessary. It's simpler and more correct to just break out of the loop once the desired blob has been flushed. --- src/common-ssh/sftp.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common-ssh/sftp.c b/src/common-ssh/sftp.c index b05409b5..d57a1826 100644 --- a/src/common-ssh/sftp.c +++ b/src/common-ssh/sftp.c @@ -586,7 +586,6 @@ static int guac_common_ssh_sftp_ls_ack_handler(guac_user* user, guac_stream* stream, char* message, guac_protocol_status status) { int bytes_read; - int blob_written = 0; char filename[GUAC_COMMON_SSH_SFTP_MAX_PATH]; LIBSSH2_SFTP_ATTRIBUTES attributes; @@ -608,8 +607,7 @@ static int guac_common_ssh_sftp_ls_ack_handler(guac_user* user, /* While directory entries remain */ while ((bytes_read = libssh2_sftp_readdir(list_state->directory, - filename, sizeof(filename), &attributes)) > 0 - && !blob_written) { + filename, sizeof(filename), &attributes)) > 0) { char absolute_path[GUAC_COMMON_SSH_SFTP_MAX_PATH]; @@ -639,9 +637,10 @@ static int guac_common_ssh_sftp_ls_ack_handler(guac_user* user, else mimetype = "application/octet-stream"; - /* Write entry */ - blob_written |= guac_common_json_write_property(user, stream, - &list_state->json_state, absolute_path, mimetype); + /* Write entry, waiting for next ack if a blob is written */ + if (guac_common_json_write_property(user, stream, + &list_state->json_state, absolute_path, mimetype)) + break; }