libproxy-0.4.15-fix-CVE-2020-25219.patch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From a83dae404feac517695c23ff43ce1e116e2bfbe0 Mon Sep 17 00:00:00 2001
  2. From: Michael Catanzaro <mcatanzaro@gnome.org>
  3. Date: Wed, 9 Sep 2020 11:12:02 -0500
  4. Subject: [PATCH] Rewrite url::recvline to be nonrecursive
  5. This function processes network input. It's semi-trusted, because the
  6. PAC ought to be trusted. But we still shouldn't allow it to control how
  7. far we recurse. A malicious PAC can cause us to overflow the stack by
  8. sending a sufficiently-long line without any '\n' character.
  9. Also, this function failed to properly handle EINTR, so let's fix that
  10. too, for good measure.
  11. Fixes #134
  12. ---
  13. libproxy/url.cpp | 28 ++++++++++++++++++----------
  14. 1 file changed, 18 insertions(+), 10 deletions(-)
  15. diff --git a/libproxy/url.cpp b/libproxy/url.cpp
  16. index ee776b2..68d69cd 100644
  17. --- a/libproxy/url.cpp
  18. +++ b/libproxy/url.cpp
  19. @@ -388,16 +388,24 @@ string url::to_string() const {
  20. return m_orig;
  21. }
  22. -static inline string recvline(int fd) {
  23. - // Read a character.
  24. - // If we don't get a character, return empty string.
  25. - // If we are at the end of the line, return empty string.
  26. - char c = '\0';
  27. -
  28. - if (recv(fd, &c, 1, 0) != 1 || c == '\n')
  29. - return "";
  30. -
  31. - return string(1, c) + recvline(fd);
  32. +static string recvline(int fd) {
  33. + string line;
  34. + int ret;
  35. +
  36. + // Reserve arbitrary amount of space to avoid small memory reallocations.
  37. + line.reserve(128);
  38. +
  39. + do {
  40. + char c;
  41. + ret = recv(fd, &c, 1, 0);
  42. + if (ret == 1) {
  43. + if (c == '\n')
  44. + return line;
  45. + line += c;
  46. + }
  47. + } while (ret == 1 || (ret == -1 && errno == EINTR));
  48. +
  49. + return line;
  50. }
  51. char* url::get_pac() {