Correctly parse v4 subsecond timestamps

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 <stefan.bruens@rwth-aachen.de>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
StefanBruens 2020-04-09 17:54:55 +00:00 committed by Jakub Jelen
parent e3e3a27863
commit 1ff6dda616

View File

@ -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) {