cherry-pick.FILE5_35-53-gd6578152.pr-62-spinpx-limit-size-of-file-printable.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. Subject: PR/62: spinpx: limit size of file_printable
  2. ID: CVE-2019-8905 CVE-2019-8907
  3. Origin: FILE5_35-53-gd6578152 <https://github.com/file/file/commit/FILE5_35-53-gd6578152>
  4. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  5. Date: Mon Feb 18 17:46:56 2019 +0000
  6. Bug-Debian: https://bugs.debian.org/922968
  7. --- a/src/file.h
  8. +++ b/src/file.h
  9. @@ -506,7 +506,7 @@
  10. size_t *);
  11. protected size_t file_pstring_length_size(const struct magic *);
  12. protected size_t file_pstring_get_length(const struct magic *, const char *);
  13. -protected char * file_printable(char *, size_t, const char *);
  14. +protected char * file_printable(char *, size_t, const char *, size_t);
  15. #ifdef __EMX__
  16. protected int file_os2_apptype(struct magic_set *, const char *, const void *,
  17. size_t);
  18. --- a/src/funcs.c
  19. +++ b/src/funcs.c
  20. @@ -623,12 +623,13 @@
  21. * convert string to ascii printable format.
  22. */
  23. protected char *
  24. -file_printable(char *buf, size_t bufsiz, const char *str)
  25. +file_printable(char *buf, size_t bufsiz, const char *str, size_t slen)
  26. {
  27. - char *ptr, *eptr;
  28. + char *ptr, *eptr = buf + bufsiz - 1;
  29. const unsigned char *s = (const unsigned char *)str;
  30. + const unsigned char *es = s + slen;
  31. - for (ptr = buf, eptr = ptr + bufsiz - 1; ptr < eptr && *s; s++) {
  32. + for (ptr = buf; ptr < eptr && s < es && *s; s++) {
  33. if (isprint(*s)) {
  34. *ptr++ = *s;
  35. continue;
  36. --- a/src/readelf.c
  37. +++ b/src/readelf.c
  38. @@ -757,7 +757,7 @@
  39. if (file_printf(ms, ", from '%.31s', pid=%u, uid=%u, "
  40. "gid=%u, nlwps=%u, lwp=%u (signal %u/code %u)",
  41. file_printable(sbuf, sizeof(sbuf),
  42. - RCAST(char *, pi.cpi_name)),
  43. + RCAST(char *, pi.cpi_name), sizeof(pi.cpi_name)),
  44. elf_getu32(swap, (uint32_t)pi.cpi_pid),
  45. elf_getu32(swap, pi.cpi_euid),
  46. elf_getu32(swap, pi.cpi_egid),
  47. @@ -1697,7 +1697,8 @@
  48. return -1;
  49. if (interp[0])
  50. if (file_printf(ms, ", interpreter %s",
  51. - file_printable(ibuf, sizeof(ibuf), interp)) == -1)
  52. + file_printable(ibuf, sizeof(ibuf), interp, sizeof(interp)))
  53. + == -1)
  54. return -1;
  55. return 0;
  56. }
  57. --- a/src/softmagic.c
  58. +++ b/src/softmagic.c
  59. @@ -634,8 +634,8 @@
  60. case FILE_LESTRING16:
  61. if (m->reln == '=' || m->reln == '!') {
  62. if (file_printf(ms, F(ms, desc, "%s"),
  63. - file_printable(sbuf, sizeof(sbuf), m->value.s))
  64. - == -1)
  65. + file_printable(sbuf, sizeof(sbuf), m->value.s,
  66. + sizeof(m->value.s))) == -1)
  67. return -1;
  68. t = ms->offset + m->vallen;
  69. }
  70. @@ -662,7 +662,8 @@
  71. }
  72. if (file_printf(ms, F(ms, desc, "%s"),
  73. - file_printable(sbuf, sizeof(sbuf), str)) == -1)
  74. + file_printable(sbuf, sizeof(sbuf), str,
  75. + sizeof(p->s) - (str - p->s))) == -1)
  76. return -1;
  77. if (m->type == FILE_PSTRING)
  78. @@ -768,7 +769,7 @@
  79. return -1;
  80. }
  81. rval = file_printf(ms, F(ms, desc, "%s"),
  82. - file_printable(sbuf, sizeof(sbuf), cp));
  83. + file_printable(sbuf, sizeof(sbuf), cp, ms->search.rm_len));
  84. free(cp);
  85. if (rval == -1)
  86. @@ -795,7 +796,8 @@
  87. break;
  88. case FILE_DER:
  89. if (file_printf(ms, F(ms, desc, "%s"),
  90. - file_printable(sbuf, sizeof(sbuf), ms->ms_value.s)) == -1)
  91. + file_printable(sbuf, sizeof(sbuf), ms->ms_value.s,
  92. + sizeof(ms->ms_value.s))) == -1)
  93. return -1;
  94. t = ms->offset;
  95. break;