aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/telnet/telnetd/utility.c
diff options
context:
space:
mode:
authorKris Kennaway <kris@FreeBSD.org>2001-07-23 22:12:45 +0000
committerKris Kennaway <kris@FreeBSD.org>2001-07-23 22:12:45 +0000
commitfe21389f84aa578cea6a4c1a0020d79959404f93 (patch)
tree394c7662af7f0d35b8ea6211b013e84e88d605d4 /crypto/telnet/telnetd/utility.c
parent5ff1744f11aaf52d3ce4a1fae0af4a2956c3995a (diff)
downloadsrc-fe21389f84aa578cea6a4c1a0020d79959404f93.tar.gz
src-fe21389f84aa578cea6a4c1a0020d79959404f93.zip
MFC: Correct semantics of output_data*() and netflush() to ensure
deterministic operation
Notes
Notes: svn path=/stable/3/; revision=80228
Diffstat (limited to 'crypto/telnet/telnetd/utility.c')
-rw-r--r--crypto/telnet/telnetd/utility.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/crypto/telnet/telnetd/utility.c b/crypto/telnet/telnetd/utility.c
index 763c881ac00e..3cc36c9b7e4a 100644
--- a/crypto/telnet/telnetd/utility.c
+++ b/crypto/telnet/telnetd/utility.c
@@ -69,10 +69,9 @@ static const char rcsid[] =
void
ttloop()
{
- void netflush();
DIAG(TD_REPORT, output_data("td: ttloop\r\n"));
- if (nfrontp-nbackp) {
+ if (nfrontp - nbackp > 0) {
netflush();
}
ncc = read(net, netibuf, sizeof netibuf);
@@ -257,10 +256,13 @@ netflush()
int n;
extern int not42;
- if ((n = nfrontp - nbackp) > 0) {
+ while ((n = nfrontp - nbackp) > 0) {
+#if 0
+ /* XXX This causes output_data() to recurse and die */
DIAG(TD_REPORT, {
n += output_data("td: netflush %d chars\r\n", n);
});
+#endif
#ifdef ENCRYPTION
if (encrypt_output) {
char *s = nclearto ? nclearto : nbackp;
@@ -293,25 +295,26 @@ netflush()
n = send(net, nbackp, n, MSG_OOB); /* URGENT data */
}
}
- }
- if (n < 0) {
- if (errno == EWOULDBLOCK || errno == EINTR)
- return;
- cleanup(0);
- }
- nbackp += n;
+ if (n == -1) {
+ if (errno == EWOULDBLOCK || errno == EINTR)
+ continue;
+ cleanup(0);
+ /* NOTREACHED */
+ }
+ nbackp += n;
#ifdef ENCRYPTION
- if (nbackp > nclearto)
- nclearto = 0;
+ if (nbackp > nclearto)
+ nclearto = 0;
#endif /* ENCRYPTION */
- if (nbackp >= neturg) {
- neturg = 0;
- }
- if (nbackp == nfrontp) {
- nbackp = nfrontp = netobuf;
+ if (nbackp >= neturg) {
+ neturg = 0;
+ }
+ if (nbackp == nfrontp) {
+ nbackp = nfrontp = netobuf;
#ifdef ENCRYPTION
- nclearto = 0;
+ nclearto = 0;
#endif /* ENCRYPTION */
+ }
}
return;
} /* end of netflush */