adjust ftruncate() logic to handle servers that reorder requests.
authordjm <djm@openbsd.org>
Sun, 30 Apr 2023 22:54:22 +0000 (22:54 +0000)
committerdjm <djm@openbsd.org>
Sun, 30 Apr 2023 22:54:22 +0000 (22:54 +0000)
commit155a002fc906a567591c1b3737aed95faad44c38
tree929785cbe5cdbaff9d926ad0e5106956533182db
parentc7ac0ddd7a56a15eae873d7d349649d5c2895ec8
adjust ftruncate() logic to handle servers that reorder requests.

sftp/scp will ftruncate the destination file after a transfer completes,
to deal with the case where a longer destination file already existed.
We tracked the highest contiguous block transferred to deal with this
case, but our naive tracking doesn't deal with servers that reorder
requests - a misfeature strictly permitted by the protocol but seldom
implemented.

Adjust the logic to ftruncate() at the highest absolute block received
when the transfer is successful. feedback deraadt@ ok markus@

prompted by https://github.com/openssh/openssh-portable/commit/9b733#commitcomment-110679778
usr.bin/ssh/sftp-client.c