CVE-2020-10188.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From 6ab007dbb1958371abff2eaaad2b26da89b3c74e Mon Sep 17 00:00:00 2001
  2. From: Yi Zhao <yi.zhao@windriver.com>
  3. Date: Fri, 24 Apr 2020 09:43:44 +0800
  4. Subject: [PATCH] telnetd/utility.c: fix CVE-2020-10188
  5. Upstream-Status: Backport
  6. [Fedora: https://src.fedoraproject.org/rpms/telnet/raw/master/f/telnet-0.17-overflow-exploit.patch]
  7. CVE: CVE-2020-10188
  8. Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
  9. ---
  10. telnetd/utility.c | 32 +++++++++++++++++++++-----------
  11. 1 file changed, 21 insertions(+), 11 deletions(-)
  12. diff --git a/telnetd/utility.c b/telnetd/utility.c
  13. index 75314cb..b9a46a6 100644
  14. --- a/telnetd/utility.c
  15. +++ b/telnetd/utility.c
  16. @@ -169,31 +169,38 @@ void ptyflush(void)
  17. */
  18. static
  19. char *
  20. -nextitem(char *current)
  21. +nextitem(char *current, const char *endp)
  22. {
  23. + if (current >= endp) {
  24. + return NULL;
  25. + }
  26. if ((*current&0xff) != IAC) {
  27. return current+1;
  28. }
  29. + if (current+1 >= endp) {
  30. + return NULL;
  31. + }
  32. switch (*(current+1)&0xff) {
  33. case DO:
  34. case DONT:
  35. case WILL:
  36. case WONT:
  37. - return current+3;
  38. + return current+3 <= endp ? current+3 : NULL;
  39. case SB: /* loop forever looking for the SE */
  40. {
  41. register char *look = current+2;
  42. - for (;;) {
  43. + while (look < endp) {
  44. if ((*look++&0xff) == IAC) {
  45. - if ((*look++&0xff) == SE) {
  46. + if (look < endp && (*look++&0xff) == SE) {
  47. return look;
  48. }
  49. }
  50. }
  51. + return NULL;
  52. }
  53. default:
  54. - return current+2;
  55. + return current+2 <= endp ? current+2 : NULL;
  56. }
  57. } /* end of nextitem */
  58. @@ -219,7 +226,7 @@ void netclear(void)
  59. register char *thisitem, *next;
  60. char *good;
  61. #define wewant(p) ((nfrontp > p) && ((*p&0xff) == IAC) && \
  62. - ((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))
  63. + (nfrontp > p+1 && (((*(p+1)&0xff) != EC) && ((*(p+1)&0xff) != EL))))
  64. #if defined(ENCRYPT)
  65. thisitem = nclearto > netobuf ? nclearto : netobuf;
  66. @@ -227,7 +234,7 @@ void netclear(void)
  67. thisitem = netobuf;
  68. #endif
  69. - while ((next = nextitem(thisitem)) <= nbackp) {
  70. + while ((next = nextitem(thisitem, nbackp)) != NULL && next <= nbackp) {
  71. thisitem = next;
  72. }
  73. @@ -239,20 +246,23 @@ void netclear(void)
  74. good = netobuf; /* where the good bytes go */
  75. #endif
  76. - while (nfrontp > thisitem) {
  77. + while (thisitem != NULL && nfrontp > thisitem) {
  78. if (wewant(thisitem)) {
  79. int length;
  80. next = thisitem;
  81. do {
  82. - next = nextitem(next);
  83. - } while (wewant(next) && (nfrontp > next));
  84. + next = nextitem(next, nfrontp);
  85. + } while (next != NULL && wewant(next) && (nfrontp > next));
  86. + if (next == NULL) {
  87. + next = nfrontp;
  88. + }
  89. length = next-thisitem;
  90. bcopy(thisitem, good, length);
  91. good += length;
  92. thisitem = next;
  93. } else {
  94. - thisitem = nextitem(thisitem);
  95. + thisitem = nextitem(thisitem, nfrontp);
  96. }
  97. }
  98. --
  99. 2.7.4