CVE-2014-8117.1.0de3251.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. Subject: Only print the description for indirect offsets if a match was found, and add the offset as the number to print
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Fri Apr 6 21:15:54 2012 +0000
  4. Origin: FILE5_11-8-g0de3251
  5. Last-Update: 2015-01-09
  6. - only print the description for indirect offsets if a match was found,
  7. and add the offset as the number to print.
  8. (prequisite for CVE-2014-8117)
  9. --- a/src/softmagic.c
  10. +++ b/src/softmagic.c
  11. @@ -1046,6 +1046,8 @@
  12. struct magic *m, size_t nbytes, unsigned int cont_level, int recursion_level)
  13. {
  14. uint32_t offset = ms->offset;
  15. + int rv;
  16. + char *sbuf, *rbuf;
  17. union VALUETYPE *p = &ms->ms_value;
  18. if (recursion_level >= 20) {
  19. @@ -1609,13 +1611,26 @@
  20. case FILE_INDIRECT:
  21. if (offset == 0)
  22. return 0;
  23. - if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
  24. - file_printf(ms, "%s", m->desc) == -1)
  25. - return -1;
  26. - if (OFFSET_OOB(nbytes, offset, 0))
  27. + if (nbytes < offset)
  28. return 0;
  29. - return file_softmagic(ms, s + offset, nbytes - offset,
  30. + sbuf = ms->o.buf;
  31. + ms->o.buf = NULL;
  32. + rv = file_softmagic(ms, s + offset, nbytes - offset,
  33. recursion_level, BINTEST);
  34. + if ((ms->flags & MAGIC_DEBUG) != 0)
  35. + fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
  36. + if (rv == 1) {
  37. + rbuf = ms->o.buf;
  38. + ms->o.buf = sbuf;
  39. + if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
  40. + file_printf(ms, m->desc, offset) == -1)
  41. + return -1;
  42. + if (file_printf(ms, "%s", rbuf) == -1)
  43. + return -1;
  44. + free(rbuf);
  45. + } else
  46. + ms->o.buf = sbuf;
  47. + return rv;
  48. case FILE_DEFAULT: /* nothing to check */
  49. default: