cherry-pick.FILE5_41-68-g497aabb2.PR-310-p870613-Don-t-use-strlcpy-to-copy-the-string-.patch 918 B

12345678910111213141516171819202122232425262728293031
  1. From: Christos Zoulas <christos@zoulas.com>
  2. Date: Mon, 14 Feb 2022 16:26:10 +0000
  3. Subject: PR/310: p870613: Don't use strlcpy to copy the string, it will try to
  4. scan the source string to find out how much space is needed the source string
  5. might not be NUL terminated.
  6. Origin: https://github.com/file/file/commit/497aabb29cd08d2a5aeb63e45798d65fcbe03502
  7. Bug: https://bugs.astron.com/view.php?id=310
  8. Bug-Debian-Security: https://security-tracker.debian.org/tracker/CVE-2022-48554
  9. ---
  10. src/funcs.c | 11 +++++++----
  11. 1 file changed, 7 insertions(+), 4 deletions(-)
  12. --- a/src/funcs.c
  13. +++ b/src/funcs.c
  14. @@ -51,9 +51,12 @@
  15. protected char *
  16. file_copystr(char *buf, size_t blen, size_t width, const char *str)
  17. {
  18. - if (++width > blen)
  19. - width = blen;
  20. - strlcpy(buf, str, width);
  21. + if (blen == 0)
  22. + return buf;
  23. + if (width >= blen)
  24. + width = blen - 1;
  25. + memcpy(buf, str, width);
  26. + buf[width] = '\0';
  27. return buf;
  28. }