sftpserver: Add missing allocation check that might cause NULL dereference

Originally reported by Wei Chong Tan <shellcurity at protonmail.com>

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Norbert Pocs <npocs@redhat.com>
This commit is contained in:
Jakub Jelen
2023-06-27 14:56:14 +02:00
parent ccc7302fc8
commit fe80f47b0a

View File

@@ -962,6 +962,12 @@ process_read(sftp_client_message client_msg)
}
buffer = malloc(client_msg->len);
if (buffer == NULL) {
ssh_set_error_oom(sftp->session);
sftp_reply_status(client_msg, SSH_FX_FAILURE, NULL);
SSH_LOG(SSH_LOG_PROTOCOL, "Failed to allocate memory for read data");
return SSH_ERROR;
}
do {
ssize_t readn = read(fd, buffer + allreadn, client_msg->len - allreadn);
if (readn < 0) {