0011-telnetd-Premature-connection-closure.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. From bc5dc7af74e6fa1c70aa4bbb1e482fd0c3663af3 Mon Sep 17 00:00:00 2001
  2. From: Mats Erik Andersson <gnu@gisladisker.se>
  3. Date: Sat, 15 Aug 2015 20:56:26 +0200
  4. Subject: [PATCH 11/60] telnetd: Premature connection closure.
  5. A change, part of 0b7e8687, but secondary to its
  6. intention, turned out to cause service rejects during
  7. conditions akin to connection flooding. Revert this
  8. particular part to gain established, good behaviour
  9. on GNU/Linux.
  10. Reported in `bug-inetutils/2015-07/msg00006.html'.
  11. ---
  12. ChangeLog | 18 ++++++++++++++++++
  13. telnetd/telnetd.c | 8 +++++++-
  14. telnetd/utility.c | 8 ++++++++
  15. 3 files changed, 33 insertions(+), 1 deletion(-)
  16. diff --git a/ChangeLog b/ChangeLog
  17. index 73b281b9..03bb8a78 100644
  18. --- a/ChangeLog
  19. +++ b/ChangeLog
  20. @@ -1,3 +1,21 @@
  21. +2015-08-15 Mats Erik Andersson <gnu@gisladisker.se>
  22. +
  23. + telnetd: Premature connection closure.
  24. + When many connections are attempted in quick succession,
  25. + a substantial number of them are cancelled. This does not
  26. + appear for manual use cases, but for contrived automated
  27. + set-ups. The cause seems to be a change in the evaluation
  28. + of pty_read(), which was done to coincide with the condition
  29. + in use by the original BSD implementation. Issue reported and
  30. + suggested by Chris Severance in
  31. + http://lists.gnu.org/archive/html/bug-inetutils/2015-07/msg00006.html
  32. +
  33. + * telnetd/telnetd.c (telnetd_run): Break the loop only by the
  34. + stronger condition `pty_read() < 0', i.e., only on non-masked
  35. + read errors. This reverts a change introduced in 2015-03-15.
  36. + * telnetd/utility.c (pty_read): Add a comment that the read
  37. + errors EWOULDBLOCK, EAGAIN, and EIO are treated specially.
  38. +
  39. 2015-08-07 Mats Erik Andersson <gnu@gisladisker.se>
  40. ifconfig: Statistics for BSD systems.
  41. diff --git a/telnetd/telnetd.c b/telnetd/telnetd.c
  42. index faecc072..0bf102ac 100644
  43. --- a/telnetd/telnetd.c
  44. +++ b/telnetd/telnetd.c
  45. @@ -662,7 +662,13 @@ telnetd_run (void)
  46. if (FD_ISSET (pty, &ibits))
  47. {
  48. /* Something to read from the pty... */
  49. - if (pty_read () <= 0)
  50. +
  51. + /* Observe that pty_read() is masking a few select
  52. + * read errors with the return value 0. Let them
  53. + * pass for further manipulation. Issue reported in
  54. + * http://lists.gnu.org/archive/html/bug-inetutils/2015-07/msg00006.html
  55. + */
  56. + if (pty_read () < 0)
  57. break;
  58. /* The first byte is now TIOCPKT data. Peek at it. */
  59. diff --git a/telnetd/utility.c b/telnetd/utility.c
  60. index e7ffb8ed..e493dff2 100644
  61. --- a/telnetd/utility.c
  62. +++ b/telnetd/utility.c
  63. @@ -372,6 +372,14 @@ pty_input_putback (const char *str, size_t len)
  64. return 0;
  65. }
  66. +/* pty_read()
  67. + *
  68. + * Read errors EWOULDBLOCK, EAGAIN, and EIO are
  69. + * tweeked into reporting zero bytes input.
  70. + * In particular, EIO is known to appear when
  71. + * reading off the master side, before having
  72. + * an active slave side.
  73. + */
  74. int
  75. pty_read (void)
  76. {
  77. --
  78. 2.26.0.292.g33ef6b2f38