cherry-pick.FILE5_35-53-gd6578152.pr-62-spinpx-limit-size-of-file-printable.patch 3.0 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/901351
  7. --- a/src/file.h
  8. +++ b/src/file.h
  9. @@ -491,7 +491,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. @@ -581,12 +581,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. @@ -725,7 +725,7 @@
  39. */
  40. if (file_printf(ms, ", from '%.31s'",
  41. file_printable(sbuf, sizeof(sbuf),
  42. - (const char *)&nbuf[doff + 0x7c])) == -1)
  43. + (const char *)&nbuf[doff + 0x7c], 32)) == -1)
  44. return 1;
  45. /*
  46. @@ -1543,7 +1543,8 @@
  47. return -1;
  48. if (interp[0])
  49. if (file_printf(ms, ", interpreter %s",
  50. - file_printable(ibuf, sizeof(ibuf), interp)) == -1)
  51. + file_printable(ibuf, sizeof(ibuf), interp, strlen(interp)))
  52. + == -1)
  53. return -1;
  54. return 0;
  55. }
  56. --- a/src/softmagic.c
  57. +++ b/src/softmagic.c
  58. @@ -544,8 +544,8 @@
  59. case FILE_LESTRING16:
  60. if (m->reln == '=' || m->reln == '!') {
  61. if (file_printf(ms, F(ms, m, "%s"),
  62. - file_printable(sbuf, sizeof(sbuf), m->value.s))
  63. - == -1)
  64. + file_printable(sbuf, sizeof(sbuf), m->value.s,
  65. + sizeof(m->value.s))) == -1)
  66. return -1;
  67. t = ms->offset + m->vallen;
  68. }
  69. @@ -572,7 +572,8 @@
  70. }
  71. if (file_printf(ms, F(ms, m, "%s"),
  72. - file_printable(sbuf, sizeof(sbuf), str)) == -1)
  73. + file_printable(sbuf, sizeof(sbuf), str,
  74. + sizeof(p->s) - (str - p->s))) == -1)
  75. return -1;
  76. if (m->type == FILE_PSTRING)
  77. @@ -678,7 +679,7 @@
  78. return -1;
  79. }
  80. rval = file_printf(ms, F(ms, m, "%s"),
  81. - file_printable(sbuf, sizeof(sbuf), cp));
  82. + file_printable(sbuf, sizeof(sbuf), cp, ms->search.rm_len));
  83. free(cp);
  84. if (rval == -1)
  85. @@ -705,7 +706,8 @@
  86. break;
  87. case FILE_DER:
  88. if (file_printf(ms, F(ms, m, "%s"),
  89. - file_printable(sbuf, sizeof(sbuf), ms->ms_value.s)) == -1)
  90. + file_printable(sbuf, sizeof(sbuf), ms->ms_value.s,
  91. + sizeof(ms->ms_value.s))) == -1)
  92. return -1;
  93. t = ms->offset;
  94. break;