1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-11-21 14:00:51 +03:00

sftp: repair mtime from e1ead35e47

A regression from e1ead35e47 broke the SFTP mtime logic in
sftp_bin2attr

Also simplified the _libssh2_get_u32/u64 functions slightly.

Closes #342
This commit is contained in:
Daniel Stenberg
2019-03-24 23:10:03 +01:00
parent 87fc75b23d
commit 38818082c1
2 changed files with 10 additions and 15 deletions

View File

@@ -736,15 +736,11 @@ void _libssh2_string_buf_free(LIBSSH2_SESSION *session, struct string_buf *buf)
int _libssh2_get_u32(struct string_buf *buf, uint32_t *out) int _libssh2_get_u32(struct string_buf *buf, uint32_t *out)
{ {
unsigned char *p = NULL;
if(!_libssh2_check_length(buf, 4)) { if(!_libssh2_check_length(buf, 4)) {
return -1; return -1;
} }
p = buf->dataptr; *out = _libssh2_ntohu32(buf->dataptr);
*out = (((uint32_t) p[0]) << 24) + (((uint32_t) p[1]) << 16) +
(((uint32_t) p[2]) << 8) + ((uint32_t) p[3]);
buf->dataptr += 4; buf->dataptr += 4;
buf->offset += 4; buf->offset += 4;
return 0; return 0;
@@ -752,12 +748,11 @@ int _libssh2_get_u32(struct string_buf *buf, uint32_t *out)
int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out) int _libssh2_get_u64(struct string_buf *buf, libssh2_uint64_t *out)
{ {
unsigned char *p = buf->dataptr;
if(!_libssh2_check_length(buf, 8)) { if(!_libssh2_check_length(buf, 8)) {
return -1; return -1;
} }
*out = _libssh2_ntohu64(p); *out = _libssh2_ntohu64(buf->dataptr);
buf->dataptr += 8; buf->dataptr += 8;
buf->offset += 8; buf->offset += 8;
return 0; return 0;

View File

@@ -719,7 +719,7 @@ sftp_bin2attr(LIBSSH2_SFTP_ATTRIBUTES *attrs, const unsigned char *p,
return LIBSSH2_ERROR_BUFFER_TOO_SMALL; return LIBSSH2_ERROR_BUFFER_TOO_SMALL;
} }
attrs->atime = atime; attrs->atime = atime;
attrs->atime = mtime; attrs->mtime = mtime;
} }
return (buf.dataptr - buf.data); return (buf.dataptr - buf.data);