From 69e97057c7ed6e2ca0abb5f86ec43e4fcc4733af Mon Sep 17 00:00:00 2001 From: StefanBruens Date: Thu, 9 Apr 2020 17:54:55 +0000 Subject: [PATCH] Correctly parse v4 subsecond timestamps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All subsecond timestamps are only in the packets if both the SUBSECOND_TIMES flag and the timestamp flag, e.g. ATTR_ACCESSTIME are set. SUBSECOND_TIMES are not very common across server implementations (e.g. openssh does not include it, nor does libssh's sftpserver implementation), but this interpretation of the SFTP protocol draft is used by WinSCP and lftp. Fixes T219. Signed-off-by: Stefan BrĂ¼ns Reviewed-by: Jakub Jelen (cherry picked from commit 1ff6dda616ecb6327256003d5c0ee7ddd40bc783) --- src/sftp.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index b64aad61..9a10b075 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1173,13 +1173,13 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf, break; } attr->atime64 = ntohll(attr->atime64); - } - if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { - if (ssh_buffer_get_u32(buf, &attr->atime_nseconds) != 4) { - break; + if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { + if (ssh_buffer_get_u32(buf, &attr->atime_nseconds) != 4) { + break; + } + attr->atime_nseconds = ntohl(attr->atime_nseconds); } - attr->atime_nseconds = ntohl(attr->atime_nseconds); } if (flags & SSH_FILEXFER_ATTR_CREATETIME) { @@ -1187,13 +1187,13 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf, break; } attr->createtime = ntohll(attr->createtime); - } - if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { - if (ssh_buffer_get_u32(buf, &attr->createtime_nseconds) != 4) { - break; + if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { + if (ssh_buffer_get_u32(buf, &attr->createtime_nseconds) != 4) { + break; + } + attr->createtime_nseconds = ntohl(attr->createtime_nseconds); } - attr->createtime_nseconds = ntohl(attr->createtime_nseconds); } if (flags & SSH_FILEXFER_ATTR_MODIFYTIME) { @@ -1201,13 +1201,13 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf, break; } attr->mtime64 = ntohll(attr->mtime64); - } - if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { - if (ssh_buffer_get_u32(buf, &attr->mtime_nseconds) != 4) { - break; + if (flags & SSH_FILEXFER_ATTR_SUBSECOND_TIMES) { + if (ssh_buffer_get_u32(buf, &attr->mtime_nseconds) != 4) { + break; + } + attr->mtime_nseconds = ntohl(attr->mtime_nseconds); } - attr->mtime_nseconds = ntohl(attr->mtime_nseconds); } if (flags & SSH_FILEXFER_ATTR_ACL) {