1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

sftp.c: Avoid null dereference

Issue found by covscan (gcc analyzer)

Signed-off-by: Norbert Pocs <npocs@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
Norbert Pocs
2023-05-19 12:02:52 +02:00
parent 96d7616166
commit 009bbc0546

View File

@@ -1755,6 +1755,10 @@ static int sftp_handle_close(sftp_session sftp, ssh_string handle)
int sftp_close(sftp_file file){ int sftp_close(sftp_file file){
int err = SSH_NO_ERROR; int err = SSH_NO_ERROR;
if (file == NULL) {
return err;
}
SAFE_FREE(file->name); SAFE_FREE(file->name);
if (file->handle){ if (file->handle){
err = sftp_handle_close(file->sftp,file->handle); err = sftp_handle_close(file->sftp,file->handle);
@@ -1917,7 +1921,7 @@ void sftp_file_set_blocking(sftp_file handle){
/* Read from a file using an opened sftp file handle. */ /* Read from a file using an opened sftp file handle. */
ssize_t sftp_read(sftp_file handle, void *buf, size_t count) { ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
sftp_session sftp = handle->sftp; sftp_session sftp;
sftp_message msg = NULL; sftp_message msg = NULL;
sftp_status_message status; sftp_status_message status;
ssh_string datastring; ssh_string datastring;
@@ -1926,6 +1930,11 @@ ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
uint32_t id; uint32_t id;
int rc; int rc;
if (handle == NULL) {
return -1;
}
sftp = handle->sftp;
if (handle->eof) { if (handle->eof) {
return 0; return 0;
} }
@@ -2147,7 +2156,7 @@ int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
} }
ssize_t sftp_write(sftp_file file, const void *buf, size_t count) { ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
sftp_session sftp = file->sftp; sftp_session sftp;
sftp_message msg = NULL; sftp_message msg = NULL;
sftp_status_message status; sftp_status_message status;
ssh_buffer buffer; ssh_buffer buffer;
@@ -2156,6 +2165,11 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
size_t packetlen; size_t packetlen;
int rc; int rc;
if (file == NULL) {
return -1;
}
sftp = file->sftp;
buffer = ssh_buffer_new(); buffer = ssh_buffer_new();
if (buffer == NULL) { if (buffer == NULL) {
ssh_set_error_oom(sftp->session); ssh_set_error_oom(sftp->session);