0001-Do-not-write-after-the-end-of-the-array-and-overwrit.patch 854 B

1234567891011121314151617181920212223242526272829303132333435
  1. From a868bacb46e3c900530bed47a1c6f85b0fbe701c Mon Sep 17 00:00:00 2001
  2. From: nicm <nicm>
  3. Date: Thu, 29 Oct 2020 16:33:01 +0000
  4. Subject: [PATCH] Do not write after the end of the array and overwrite the
  5. stack when colon-separated SGR sequences contain empty arguments. Reported by
  6. Sergey Nizovtsev.
  7. [Peter: Fixes CVE-2020-27347]
  8. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  9. ---
  10. input.c | 7 ++++++-
  11. 1 file changed, 6 insertions(+), 1 deletion(-)
  12. diff --git a/input.c b/input.c
  13. index 42a60c92..c280c0d9 100644
  14. --- a/input.c
  15. +++ b/input.c
  16. @@ -1976,8 +1976,13 @@ input_csi_dispatch_sgr_colon(struct input_ctx *ictx, u_int i)
  17. free(copy);
  18. return;
  19. }
  20. - } else
  21. + } else {
  22. n++;
  23. + if (n == nitems(p)) {
  24. + free(copy);
  25. + return;
  26. + }
  27. + }
  28. log_debug("%s: %u = %d", __func__, n - 1, p[n - 1]);
  29. }
  30. free(copy);
  31. --
  32. 2.20.1