diff options
author | Damien Miller <djm@mindrot.org> | 2013-11-08 12:28:03 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2013-11-08 12:28:03 +1100 |
commit | 727a3bfd3b5943bef9a9fd02812e9a75758d6d26 (patch) | |
tree | c9465c196ba7c575797626192d06e35a787a5c7d /sftp-client.c | |
parent | 13cfd6d68237ef844dd8e02cf9ed21268154a999 (diff) |
- djm@cvs.openbsd.org 2013/11/08 00:39:15
[auth-options.c auth2-chall.c authfd.c channels.c cipher-3des1.c]
[clientloop.c gss-genr.c monitor_mm.c packet.c schnorr.c umac.c]
[sftp-client.c sftp-glob.c]
use calloc for all structure allocations; from markus@
Diffstat (limited to 'sftp-client.c')
-rw-r--r-- | sftp-client.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/sftp-client.c b/sftp-client.c index f2ce9deb7..2f9793778 100644 --- a/sftp-client.c +++ b/sftp-client.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp-client.c,v 1.103 2013/08/09 03:39:13 djm Exp $ */ | 1 | /* $OpenBSD: sftp-client.c,v 1.108 2013/11/08 00:39:15 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -337,8 +337,7 @@ do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests, | |||
337 | Buffer msg; | 337 | Buffer msg; |
338 | struct sftp_conn *ret; | 338 | struct sftp_conn *ret; |
339 | 339 | ||
340 | ret = xcalloc(1, sizeof(*ret)); | 340 | ret = xmalloc(sizeof(*ret)); |
341 | ret->msg_id = 1; | ||
342 | ret->fd_in = fd_in; | 341 | ret->fd_in = fd_in; |
343 | ret->fd_out = fd_out; | 342 | ret->fd_out = fd_out; |
344 | ret->transfer_buflen = transfer_buflen; | 343 | ret->transfer_buflen = transfer_buflen; |
@@ -472,7 +471,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, | |||
472 | 471 | ||
473 | if (dir) { | 472 | if (dir) { |
474 | ents = 0; | 473 | ents = 0; |
475 | *dir = xmalloc(sizeof(**dir)); | 474 | *dir = xcalloc(1, sizeof(**dir)); |
476 | (*dir)[0] = NULL; | 475 | (*dir)[0] = NULL; |
477 | } | 476 | } |
478 | 477 | ||
@@ -546,7 +545,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, | |||
546 | 545 | ||
547 | if (dir) { | 546 | if (dir) { |
548 | *dir = xrealloc(*dir, ents + 2, sizeof(**dir)); | 547 | *dir = xrealloc(*dir, ents + 2, sizeof(**dir)); |
549 | (*dir)[ents] = xmalloc(sizeof(***dir)); | 548 | (*dir)[ents] = xcalloc(1, sizeof(***dir)); |
550 | (*dir)[ents]->filename = xstrdup(filename); | 549 | (*dir)[ents]->filename = xstrdup(filename); |
551 | (*dir)[ents]->longname = xstrdup(longname); | 550 | (*dir)[ents]->longname = xstrdup(longname); |
552 | memcpy(&(*dir)[ents]->a, a, sizeof(*a)); | 551 | memcpy(&(*dir)[ents]->a, a, sizeof(*a)); |
@@ -565,7 +564,7 @@ do_lsreaddir(struct sftp_conn *conn, char *path, int printflag, | |||
565 | /* Don't return partial matches on interrupt */ | 564 | /* Don't return partial matches on interrupt */ |
566 | if (interrupted && dir != NULL && *dir != NULL) { | 565 | if (interrupted && dir != NULL && *dir != NULL) { |
567 | free_sftp_dirents(*dir); | 566 | free_sftp_dirents(*dir); |
568 | *dir = xmalloc(sizeof(**dir)); | 567 | *dir = xcalloc(1, sizeof(**dir)); |
569 | **dir = NULL; | 568 | **dir = NULL; |
570 | } | 569 | } |
571 | 570 | ||
@@ -769,18 +768,16 @@ do_realpath(struct sftp_conn *conn, char *path) | |||
769 | } | 768 | } |
770 | 769 | ||
771 | int | 770 | int |
772 | do_rename(struct sftp_conn *conn, char *oldpath, char *newpath, | 771 | do_rename(struct sftp_conn *conn, char *oldpath, char *newpath) |
773 | int force_legacy) | ||
774 | { | 772 | { |
775 | Buffer msg; | 773 | Buffer msg; |
776 | u_int status, id; | 774 | u_int status, id; |
777 | int use_ext = (conn->exts & SFTP_EXT_POSIX_RENAME) && !force_legacy; | ||
778 | 775 | ||
779 | buffer_init(&msg); | 776 | buffer_init(&msg); |
780 | 777 | ||
781 | /* Send rename request */ | 778 | /* Send rename request */ |
782 | id = conn->msg_id++; | 779 | id = conn->msg_id++; |
783 | if (use_ext) { | 780 | if ((conn->exts & SFTP_EXT_POSIX_RENAME)) { |
784 | buffer_put_char(&msg, SSH2_FXP_EXTENDED); | 781 | buffer_put_char(&msg, SSH2_FXP_EXTENDED); |
785 | buffer_put_int(&msg, id); | 782 | buffer_put_int(&msg, id); |
786 | buffer_put_cstring(&msg, "posix-rename@openssh.com"); | 783 | buffer_put_cstring(&msg, "posix-rename@openssh.com"); |
@@ -792,8 +789,8 @@ do_rename(struct sftp_conn *conn, char *oldpath, char *newpath, | |||
792 | buffer_put_cstring(&msg, newpath); | 789 | buffer_put_cstring(&msg, newpath); |
793 | send_msg(conn, &msg); | 790 | send_msg(conn, &msg); |
794 | debug3("Sent message %s \"%s\" -> \"%s\"", | 791 | debug3("Sent message %s \"%s\" -> \"%s\"", |
795 | use_ext ? "posix-rename@openssh.com" : "SSH2_FXP_RENAME", | 792 | (conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" : |
796 | oldpath, newpath); | 793 | "SSH2_FXP_RENAME", oldpath, newpath); |
797 | buffer_free(&msg); | 794 | buffer_free(&msg); |
798 | 795 | ||
799 | status = get_status(conn, id); | 796 | status = get_status(conn, id); |
@@ -1108,7 +1105,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, | |||
1108 | (unsigned long long)offset, | 1105 | (unsigned long long)offset, |
1109 | (unsigned long long)offset + buflen - 1, | 1106 | (unsigned long long)offset + buflen - 1, |
1110 | num_req, max_req); | 1107 | num_req, max_req); |
1111 | req = xmalloc(sizeof(*req)); | 1108 | req = xcalloc(1, sizeof(*req)); |
1112 | req->id = conn->msg_id++; | 1109 | req->id = conn->msg_id++; |
1113 | req->len = buflen; | 1110 | req->len = buflen; |
1114 | req->offset = offset; | 1111 | req->offset = offset; |
@@ -1222,7 +1219,6 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, | |||
1222 | if (read_error) { | 1219 | if (read_error) { |
1223 | error("Couldn't read from remote file \"%s\" : %s", | 1220 | error("Couldn't read from remote file \"%s\" : %s", |
1224 | remote_path, fx2txt(status)); | 1221 | remote_path, fx2txt(status)); |
1225 | status = -1; | ||
1226 | do_close(conn, handle, handle_len); | 1222 | do_close(conn, handle, handle_len); |
1227 | } else if (write_error) { | 1223 | } else if (write_error) { |
1228 | error("Couldn't write to \"%s\": %s", local_path, | 1224 | error("Couldn't write to \"%s\": %s", local_path, |
@@ -1231,7 +1227,7 @@ do_download(struct sftp_conn *conn, char *remote_path, char *local_path, | |||
1231 | do_close(conn, handle, handle_len); | 1227 | do_close(conn, handle, handle_len); |
1232 | } else { | 1228 | } else { |
1233 | status = do_close(conn, handle, handle_len); | 1229 | status = do_close(conn, handle, handle_len); |
1234 | if (interrupted || status != SSH2_FX_OK) | 1230 | if (interrupted) |
1235 | status = -1; | 1231 | status = -1; |
1236 | /* Override umask and utimes if asked */ | 1232 | /* Override umask and utimes if asked */ |
1237 | #ifdef HAVE_FCHMOD | 1233 | #ifdef HAVE_FCHMOD |
@@ -1467,7 +1463,7 @@ do_upload(struct sftp_conn *conn, char *local_path, char *remote_path, | |||
1467 | strerror(errno)); | 1463 | strerror(errno)); |
1468 | 1464 | ||
1469 | if (len != 0) { | 1465 | if (len != 0) { |
1470 | ack = xmalloc(sizeof(*ack)); | 1466 | ack = xcalloc(1, sizeof(*ack)); |
1471 | ack->id = ++id; | 1467 | ack->id = ++id; |
1472 | ack->offset = offset; | 1468 | ack->offset = offset; |
1473 | ack->len = len; | 1469 | ack->len = len; |