Andreas Schneider
be8302e2f3
sftp: Allocate a new buffer in sftp_packet_read() if needed
...
We will move the buffer to the message instead of duplicating the
memory.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
97d2e1f4cb
sftp: Reformat sftp_read_and_dispatch()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
12fc0ea1bf
sftp: Validate the packet handle before we allocate memory
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
573eab0d51
sftp: Reformat sftp_get_message()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
0e317e612f
sftp: Use bool for is_eof in sftp_packet_read()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
01135703a3
sftp: Use 's' only in the scope it is needed
...
This revaled a bug when reading the packet type.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
c070414309
sftp: Use 16K for the transfer buffer size
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
d2cc4eccc7
sftp: Get the packet type directly from the buffer
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
38781f69b0
sftp: Limit packet size to 256 MB
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
dc4faf9952
sftp: Directly read and validate the packet size from the bufffer
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
cbbc6ddcb6
sftp: Use read_packet from sftp handle
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
a7456bf4d5
sftp: Simplify the code for reading data
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
afc14fe003
sftp: Reformat sftp_packet_read()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
79a3fcac72
sftp: Keep a ssh_packet for reading in the sftp handle
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
945afaa6b4
sftp: Remove ZERO_STRUCTP from sftp_free()
...
The structure doesn't hold any sensitive data and this would be
optimized away anyway.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
d840a05be3
sftp: Reformat sftp_free()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
662c30eb72
sftp: Reformat sftp_new()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-17 10:48:49 +02:00
Andreas Schneider
4774d2b9f7
sftp: Fix segfault in sftp_canonicalize_path()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-04 17:30:18 +02:00
Andreas Schneider
e601dbd8e3
sftp: Use ssh_buffer_pack() in sftp_fstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
f3ffd8aa41
sftp: Reformat sftp_lstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
4d98b1cd7e
sftp: Use ssh_buffer_pack() in sftp_xstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
b00a0578f9
sftp: Reformat sftp_xstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
336c097ae7
sftp: Use ssh_buffer_unpack() in sftp_canonicalize_path()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
1dd8466f66
sftp: Use ssh_buffer_pack() in sftp_canonicalize_path()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
8b19ef05f3
sftp: Reformat sftp_canonicalize_path()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
7e11e41a9f
sftp: Use sftp_buffer_pack() in sftp_fstatvfs()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
5914ea7c75
sftp: Reformat sftp_fstatvfs()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
f1e84d5e67
sftp: Use ssh_buffer_pack() in sftp_fsync()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
8e3dd09e11
sftp: Use ssh_buffer_pack() in sftp_statvfs()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
ae0afec98d
sftp: Reformat sftp_statvfs()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
0be43c333e
sftp: Use ssh_buffer_unpack() in sftp_readlink()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
83a5d3b258
sftp: Use ssh_buffer_pack() in sftp_readlink()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:23 +02:00
Andreas Schneider
bb4bdec184
sftp: Reformat sftp_readlink()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:39:16 +02:00
Andreas Schneider
e0449ba21f
sftp: Use ssh_buffer_pack() in sftp_setstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:37:24 +02:00
Andreas Schneider
8a56b90c3e
sftp: Reformat sftp_setstat()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:36:29 +02:00
Andreas Schneider
218c67a51d
sftp: Use ssh_buffer_pack() in sftp_mkdir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:36:29 +02:00
Andreas Schneider
89c525bbf1
sftp: Reformat sftp_mkdir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:36:29 +02:00
Andreas Schneider
2c0baef7d4
sftp: Use ssh_buffer_pack in sftp_open()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:34:00 +02:00
Andreas Schneider
bfb6718b50
sftp: Reformat sftp_open()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:34:00 +02:00
Andreas Schneider
d99c066a0b
sftp: Use ssh_buffer_pack() in sftp_handle_close()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:34:00 +02:00
Andreas Schneider
2844942c1b
sftp: Reformat sftp_handle_close()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:34:00 +02:00
Andreas Schneider
3a729829fd
sftp: Use ssh_buffer_pack() in sftp_readdir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:34:00 +02:00
Andreas Schneider
576fdbe1e8
sftp: Reformat sftp_readdir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:32:45 +02:00
Andreas Schneider
87df9cfc5d
sftp: Use ssh_buffer_pack() in sftp_opendir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:32:23 +02:00
Andreas Schneider
ea375d1605
sftp: Reformat sftp_opendir()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-09-03 18:32:23 +02:00
Andreas Schneider
509331ec81
sftp: Use strndup()
...
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-08-29 19:04:44 +02:00
Jakub Jelen
ae3825dfb2
sftp: Avoid race condition reading incomplete data messages
...
This changes amends f561e6bcb3 which
introduces same check in one place, but miss it in other two places.
We encountered this issue with qemu using SFTP to transfer large
data chunks and in some cases, the file transfer was interrupted
without any reason. From the debug messages, it showed up that
last part of data message/packet was not handled in the time
of the sftp_read() call, therefore the ssh_channel_read() returned
zero (there was no more data to read yet), which made the whole
transfer fail hard instead of retrying later.
The proposed change is reusing the code from previously referenced
commit also in the other places.
Signed-off-by: Jakub Jelen <jjelen@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-08-27 09:29:24 +02:00
Jakub Jelen
a0214dfc9a
sftp: Fix the debug message in sftp_enqueue()
...
This fixes the assignment of variables to comments and makes
the output symmetric with sftp_dequeue().
Signed-off-by: Jakub Jelen <jjelen@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-08-18 10:00:37 +02:00
Andreas Schneider
24aef4fbf1
sftp: Add missing size checks
...
CID 1238630
Signed-off-by: Andreas Schneider <asn@cryptomilk.org >
2018-08-06 09:36:50 +02:00
Pino Toscano
12284b75fa
buffer: Add and use ssh_buffer_allocate_size()
...
Add a small helper for ssh_buffer to ensure that the buffer has a
certain amount of space already preallocated. This can be useful in case
it is known how much data is going to be added to a buffer, to avoid
multiple reallocations.
Make use of it in few places in the library.
Signed-off-by: Pino Toscano <ptoscano@redhat.com >
Reviewed-by: Andreas Schneider <asn@cryptomilk.org >
2018-08-01 11:04:33 +02:00