sftp_aio.c, sftp.h: Add capping to sftp aio write API

Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Eshan Kelkar
2023-12-07 10:44:58 +05:30
committed by Jakub Jelen
parent 91990f9dfa
commit 188a9cf68f
2 changed files with 26 additions and 17 deletions

View File

@@ -307,10 +307,10 @@ ssize_t sftp_aio_wait_read(sftp_aio *aio,
return SSH_ERROR; /* not reached */
}
int sftp_aio_begin_write(sftp_file file,
const void *buf,
size_t len,
sftp_aio *aio)
ssize_t sftp_aio_begin_write(sftp_file file,
const void *buf,
size_t len,
sftp_aio *aio)
{
sftp_session sftp = NULL;
ssh_buffer buffer = NULL;
@@ -341,6 +341,11 @@ int sftp_aio_begin_write(sftp_file file,
return SSH_ERROR;
}
/* Apply a cap on the length a user is allowed to write */
if (len > sftp->limits->max_write_length) {
len = sftp->limits->max_write_length;
}
if (aio == NULL) {
ssh_set_error(sftp->session, SSH_FATAL,
"Invalid argument, NULL passed instead of a pointer to "
@@ -394,7 +399,7 @@ int sftp_aio_begin_write(sftp_file file,
/* Assume we wrote len bytes to the file */
file->offset += len;
*aio = aio_handle;
return SSH_OK;
return len;
}
ssize_t sftp_aio_wait_write(sftp_aio *aio)