diff options
author | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2009-12-29 21:32:03 +0000 |
commit | 04942aa41fa94ec6f2c3ce1d348f600f31bb7c78 (patch) | |
tree | af8e928bd79d3f2d0219bb5b2c78b573ec31d94c /sftp-client.c | |
parent | 9ad7b718d42e43f3a285fcbc8f91193931fce324 (diff) | |
parent | 16704d57999d987fb8d9ba53379841a79f016d67 (diff) |
import openssh-4.2p1-gsskex-20050926-2.patch
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/sftp-client.c b/sftp-client.c index d894a11f2..afbd1e6f3 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -20,7 +20,7 @@ | |||
20 | /* XXX: copy between two remote sites */ | 20 | /* XXX: copy between two remote sites */ |
21 | 21 | ||
22 | #include "includes.h" | 22 | #include "includes.h" |
23 | RCSID("$OpenBSD: sftp-client.c,v 1.52 2004/11/25 22:22:14 markus Exp $"); | 23 | RCSID("$OpenBSD: sftp-client.c,v 1.57 2005/07/27 10:39:03 dtucker Exp $"); |
24 | 24 | ||
25 | #include "openbsd-compat/sys-queue.h" | 25 | #include "openbsd-compat/sys-queue.h" |
26 | 26 | ||
@@ -64,10 +64,10 @@ send_msg(int fd, Buffer *m) | |||
64 | 64 | ||
65 | /* Send length first */ | 65 | /* Send length first */ |
66 | PUT_32BIT(mlen, buffer_len(m)); | 66 | PUT_32BIT(mlen, buffer_len(m)); |
67 | if (atomicio(vwrite, fd, mlen, sizeof(mlen)) <= 0) | 67 | if (atomicio(vwrite, fd, mlen, sizeof(mlen)) != sizeof(mlen)) |
68 | fatal("Couldn't send packet: %s", strerror(errno)); | 68 | fatal("Couldn't send packet: %s", strerror(errno)); |
69 | 69 | ||
70 | if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) <= 0) | 70 | if (atomicio(vwrite, fd, buffer_ptr(m), buffer_len(m)) != buffer_len(m)) |
71 | fatal("Couldn't send packet: %s", strerror(errno)); | 71 | fatal("Couldn't send packet: %s", strerror(errno)); |
72 | 72 | ||
73 | buffer_clear(m); | 73 | buffer_clear(m); |
@@ -76,26 +76,27 @@ send_msg(int fd, Buffer *m) | |||
76 | static void | 76 | static void |
77 | get_msg(int fd, Buffer *m) | 77 | get_msg(int fd, Buffer *m) |
78 | { | 78 | { |
79 | ssize_t len; | ||
80 | u_int msg_len; | 79 | u_int msg_len; |
81 | 80 | ||
82 | buffer_append_space(m, 4); | 81 | buffer_append_space(m, 4); |
83 | len = atomicio(read, fd, buffer_ptr(m), 4); | 82 | if (atomicio(read, fd, buffer_ptr(m), 4) != 4) { |
84 | if (len == 0) | 83 | if (errno == EPIPE) |
85 | fatal("Connection closed"); | 84 | fatal("Connection closed"); |
86 | else if (len == -1) | 85 | else |
87 | fatal("Couldn't read packet: %s", strerror(errno)); | 86 | fatal("Couldn't read packet: %s", strerror(errno)); |
87 | } | ||
88 | 88 | ||
89 | msg_len = buffer_get_int(m); | 89 | msg_len = buffer_get_int(m); |
90 | if (msg_len > MAX_MSG_LENGTH) | 90 | if (msg_len > MAX_MSG_LENGTH) |
91 | fatal("Received message too long %u", msg_len); | 91 | fatal("Received message too long %u", msg_len); |
92 | 92 | ||
93 | buffer_append_space(m, msg_len); | 93 | buffer_append_space(m, msg_len); |
94 | len = atomicio(read, fd, buffer_ptr(m), msg_len); | 94 | if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) { |
95 | if (len == 0) | 95 | if (errno == EPIPE) |
96 | fatal("Connection closed"); | 96 | fatal("Connection closed"); |
97 | else if (len == -1) | 97 | else |
98 | fatal("Read packet: %s", strerror(errno)); | 98 | fatal("Read packet: %s", strerror(errno)); |
99 | } | ||
99 | } | 100 | } |
100 | 101 | ||
101 | static void | 102 | static void |
@@ -310,7 +311,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, | |||
310 | SFTP_DIRENT ***dir) | 311 | SFTP_DIRENT ***dir) |
311 | { | 312 | { |
312 | Buffer msg; | 313 | Buffer msg; |
313 | u_int type, id, handle_len, i, expected_id, ents = 0; | 314 | u_int count, type, id, handle_len, i, expected_id, ents = 0; |
314 | char *handle; | 315 | char *handle; |
315 | 316 | ||
316 | id = conn->msg_id++; | 317 | id = conn->msg_id++; |
@@ -334,8 +335,6 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, | |||
334 | } | 335 | } |
335 | 336 | ||
336 | for (; !interrupted;) { | 337 | for (; !interrupted;) { |
337 | int count; | ||
338 | |||
339 | id = expected_id = conn->msg_id++; | 338 | id = expected_id = conn->msg_id++; |
340 | 339 | ||
341 | debug3("Sending SSH2_FXP_READDIR I:%u", id); | 340 | debug3("Sending SSH2_FXP_READDIR I:%u", id); |
@@ -743,10 +742,10 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, | |||
743 | Attrib junk, *a; | 742 | Attrib junk, *a; |
744 | Buffer msg; | 743 | Buffer msg; |
745 | char *handle; | 744 | char *handle; |
746 | int local_fd, status, num_req, max_req, write_error; | 745 | int local_fd, status = 0, write_error; |
747 | int read_error, write_errno; | 746 | int read_error, write_errno; |
748 | u_int64_t offset, size; | 747 | u_int64_t offset, size; |
749 | u_int handle_len, mode, type, id, buflen; | 748 | u_int handle_len, mode, type, id, buflen, num_req, max_req; |
750 | off_t progress_counter; | 749 | off_t progress_counter; |
751 | struct request { | 750 | struct request { |
752 | u_int id; | 751 | u_int id; |
@@ -856,7 +855,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, | |||
856 | debug3("Received reply T:%u I:%u R:%d", type, id, max_req); | 855 | debug3("Received reply T:%u I:%u R:%d", type, id, max_req); |
857 | 856 | ||
858 | /* Find the request in our queue */ | 857 | /* Find the request in our queue */ |
859 | for(req = TAILQ_FIRST(&requests); | 858 | for (req = TAILQ_FIRST(&requests); |
860 | req != NULL && req->id != id; | 859 | req != NULL && req->id != id; |
861 | req = TAILQ_NEXT(req, tq)) | 860 | req = TAILQ_NEXT(req, tq)) |
862 | ; | 861 | ; |
@@ -1109,7 +1108,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, | |||
1109 | debug3("SSH2_FXP_STATUS %d", status); | 1108 | debug3("SSH2_FXP_STATUS %d", status); |
1110 | 1109 | ||
1111 | /* Find the request in our queue */ | 1110 | /* Find the request in our queue */ |
1112 | for(ack = TAILQ_FIRST(&acks); | 1111 | for (ack = TAILQ_FIRST(&acks); |
1113 | ack != NULL && ack->id != r_id; | 1112 | ack != NULL && ack->id != r_id; |
1114 | ack = TAILQ_NEXT(ack, tq)) | 1113 | ack = TAILQ_NEXT(ack, tq)) |
1115 | ; | 1114 | ; |
@@ -1127,7 +1126,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, | |||
1127 | goto done; | 1126 | goto done; |
1128 | } | 1127 | } |
1129 | debug3("In write loop, ack for %u %u bytes at %llu", | 1128 | debug3("In write loop, ack for %u %u bytes at %llu", |
1130 | ack->id, ack->len, (unsigned long long)ack->offset); | 1129 | ack->id, ack->len, (unsigned long long)ack->offset); |
1131 | ++ackid; | 1130 | ++ackid; |
1132 | xfree(ack); | 1131 | xfree(ack); |
1133 | } | 1132 | } |