algorithm. Make sure the sender does not run ahead of itself and end
stalling in a read from network that never shows up. Instead ensure
that all queued data is pushed out before accepting new data.
Problem found by and fix developed with Kyle Evans (kevans freebsd.org)
OK tb@ deraadt@
-/* $OpenBSD: sender.c,v 1.30 2021/08/29 13:43:46 claudio Exp $ */
+/* $OpenBSD: sender.c,v 1.31 2024/02/19 16:39:18 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
* poll events on demand.
*/
- pfd[0].fd = fdin; /* from receiver */
+ pfd[0].fd = -1; /* from receiver */
pfd[0].events = POLLIN;
pfd[1].fd = -1; /* to receiver */
pfd[1].events = POLLOUT;
pfd[2].events = POLLIN;
for (;;) {
- assert(pfd[0].fd != -1);
+ /* disable recevier until all buffered data was sent */
+ if (pfd[1].fd != -1 && wbufsz > 0)
+ pfd[0].fd = -1;
+ else
+ pfd[0].fd = fdin;
if ((c = poll(pfd, 3, poll_timeout)) == -1) {
ERR("poll");
goto out;