0004-iconv-fix-erroneous-input-validation-in-EUC-KR-decod.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. From e5adcd97b5196e29991b524237381a0202a60659 Mon Sep 17 00:00:00 2001
  2. From: Rich Felker <dalias@aerifal.cx>
  3. Date: Sun, 9 Feb 2025 10:07:19 -0500
  4. Subject: [PATCH] iconv: fix erroneous input validation in EUC-KR decoder
  5. as a result of incorrect bounds checking on the lead byte being
  6. decoded, certain invalid inputs which should produce an encoding
  7. error, such as "\xc8\x41", instead produced out-of-bounds loads from
  8. the ksc table.
  9. in a worst case, the loaded value may not be a valid unicode scalar
  10. value, in which case, if the output encoding was UTF-8, wctomb would
  11. return (size_t)-1, causing an overflow in the output pointer and
  12. remaining buffer size which could clobber memory outside of the output
  13. buffer.
  14. bug report was submitted in private by Nick Wellnhofer on account of
  15. potential security implications.
  16. Upstream: https://git.musl-libc.org/cgit/musl/commit/?id=e5adcd97b5196e29991b524237381a0202a60659
  17. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  18. ---
  19. src/locale/iconv.c | 2 +-
  20. 1 file changed, 1 insertion(+), 1 deletion(-)
  21. diff --git a/src/locale/iconv.c b/src/locale/iconv.c
  22. index 9605c8e9..008c93f0 100644
  23. --- a/src/locale/iconv.c
  24. +++ b/src/locale/iconv.c
  25. @@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri
  26. if (c >= 93 || d >= 94) {
  27. c += (0xa1-0x81);
  28. d += 0xa1;
  29. - if (c >= 93 || c>=0xc6-0x81 && d>0x52)
  30. + if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52)
  31. goto ilseq;
  32. if (d-'A'<26) d = d-'A';
  33. else if (d-'a'<26) d = d-'a'+26;
  34. --
  35. 2.39.5