From fb1b0b96533e94d5d21c5d318c82c5a0198104ec Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Mon, 28 Sep 2026 13:17:53 +0200 Subject: [PATCH] vfs/sftpfs: Always zero-initialize struct stat and set st_blksize copy_file_file() uses the st_blksize member of struct stat for buffer size calculation. Uninitialized value results in a memory allocation error. This change always zero-initializes the struct, so one non-zero initialization of st_nlink needs to be moved after a call that now clears the struct. Signed-off-by: Phil Krylov --- src/vfs/sftpfs/internal.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/vfs/sftpfs/internal.c b/src/vfs/sftpfs/internal.c index 8507fcf42d..da2a4061ab 100644 --- a/src/vfs/sftpfs/internal.c +++ b/src/vfs/sftpfs/internal.c @@ -248,6 +248,8 @@ sftpfs_op_init (sftpfs_super_t **super, const vfs_path_element_t **path_element, void sftpfs_attr_to_stat (const LIBSSH2_SFTP_ATTRIBUTES *attrs, struct stat *s) { + memset (s, 0, sizeof (struct stat)); + if ((attrs->flags & LIBSSH2_SFTP_ATTR_UIDGID) != 0) { s->st_uid = attrs->uid; @@ -263,10 +265,9 @@ sftpfs_attr_to_stat (const LIBSSH2_SFTP_ATTRIBUTES *attrs, struct stat *s) } if ((attrs->flags & LIBSSH2_SFTP_ATTR_SIZE) != 0) - { s->st_size = attrs->filesize; - sftpfs_blksize (s); - } + + sftpfs_blksize (s); if ((attrs->flags & LIBSSH2_SFTP_ATTR_PERMISSIONS) != 0) s->st_mode = attrs->permissions; @@ -321,8 +322,8 @@ sftpfs_stat (const vfs_path_t *vpath, struct stat *buf, GError **mcerror) res = sftpfs_stat_init (&super, &path_element, vpath, mcerror, LIBSSH2_SFTP_STAT, &attrs); if (res >= 0) { - buf->st_nlink = 1; sftpfs_attr_to_stat (&attrs, buf); + buf->st_nlink = 1; res = 0; }