Skip to content

Commit

Permalink
sftp_async_write: bit cleanup error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
upa committed Mar 9, 2024
1 parent 0e80f08 commit 9d02fc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions patch/libssh-0.10.6-2-g6f1b1e76.patch
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ index 8c509699..307388e5 100644
session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH |
SSH_OPT_FLAG_PUBKEY_AUTH |
diff --git a/src/sftp.c b/src/sftp.c
index e01012a8..702623a0 100644
index e01012a8..3b86c3c6 100644
--- a/src/sftp.c
+++ b/src/sftp.c
@@ -2228,6 +2228,132 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
@@ -2228,6 +2228,135 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
return -1; /* not reached */
}

Expand Down Expand Up @@ -434,7 +434,8 @@ index e01012a8..702623a0 100644
+
+ buffer = ssh_buffer_new_size(buf_sz, HEADROOM);
+ if (buffer == NULL) {
+ ssh_set_error_oom(sftp->session);
+ ssh_set_error(sftp->session, SSH_FATAL,
+ "ssh_buffer_new_size failed: Out of Memory");
+ return -1;
+ }
+
Expand All @@ -448,14 +449,16 @@ index e01012a8..702623a0 100644
+ count); /* len of datastring */
+
+ if (rc != SSH_OK){
+ ssh_set_error_oom(sftp->session);
+ ssh_set_error(sftp->session, SSH_FATAL,
+ "ssh_buffer_pack failed: Out of Memory");
+ ssh_buffer_free(buffer);
+ return SSH_ERROR;
+ }
+
+ actual = ssh_buffer_add_func(buffer, f, count, userdata);
+ if (actual < 0){
+ ssh_set_error_oom(sftp->session);
+ ssh_set_error(sftp->session, SSH_FATAL,
+ "ssh_buffer_add_func failed: %s", strerror(errno));
+ ssh_buffer_free(buffer);
+ return SSH_ERROR;
+ }
Expand Down
8 changes: 4 additions & 4 deletions src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ static int copy_chunk_l2r(struct chunk *c, int fd, sftp_file sf, int nr_ahead, i
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
&reqs[idx].id);
if (reqs[idx].len < 0) {
priv_set_errv("sftp_async_write: %s or %s",
sftp_get_ssh_error(sf->sftp), strerrno());
priv_set_errv("sftp_async_write: %s",
sftp_get_ssh_error(sf->sftp));
return -1;
}
thrown -= reqs[idx].len;
Expand All @@ -394,8 +394,8 @@ static int copy_chunk_l2r(struct chunk *c, int fd, sftp_file sf, int nr_ahead, i
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
&reqs[idx].id);
if (reqs[idx].len < 0) {
priv_set_errv("sftp_async_write: %s or %s",
sftp_get_ssh_error(sf->sftp), strerrno());
priv_set_errv("sftp_async_write: %s",
sftp_get_ssh_error(sf->sftp));
return -1;
}
thrown -= reqs[idx].len;
Expand Down

0 comments on commit 9d02fc9

Please sign in to comment.