CVE-2014-8117.1.0de3251.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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-05
  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. diff --git a/src/softmagic.c b/src/softmagic.c
  10. index c77b619..bcd7f02 100644
  11. --- a/src/softmagic.c
  12. +++ b/src/softmagic.c
  13. @@ -1041,6 +1041,8 @@ mget(struct magic_set *ms, const unsigned char *s,
  14. int recursion_level)
  15. {
  16. uint32_t offset = ms->offset;
  17. + int rv;
  18. + char *sbuf, *rbuf;
  19. union VALUETYPE *p = &ms->ms_value;
  20. if (recursion_level >= 20) {
  21. @@ -1604,13 +1606,26 @@ mget(struct magic_set *ms, const unsigned char *s,
  22. case FILE_INDIRECT:
  23. if (offset == 0)
  24. return 0;
  25. - if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
  26. - file_printf(ms, "%s", m->desc) == -1)
  27. - return -1;
  28. - if (OFFSET_OOB(nbytes, offset, 0))
  29. + if (nbytes < offset)
  30. return 0;
  31. - return file_softmagic(ms, s + offset, nbytes - offset,
  32. + sbuf = ms->o.buf;
  33. + ms->o.buf = NULL;
  34. + rv = file_softmagic(ms, s + offset, nbytes - offset,
  35. recursion_level, BINTEST, text);
  36. + if ((ms->flags & MAGIC_DEBUG) != 0)
  37. + fprintf(stderr, "indirect @offs=%u[%d]\n", offset, rv);
  38. + if (rv == 1) {
  39. + rbuf = ms->o.buf;
  40. + ms->o.buf = sbuf;
  41. + if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
  42. + file_printf(ms, m->desc, offset) == -1)
  43. + return -1;
  44. + if (file_printf(ms, "%s", rbuf) == -1)
  45. + return -1;
  46. + free(rbuf);
  47. + } else
  48. + ms->o.buf = sbuf;
  49. + return rv;
  50. case FILE_DEFAULT: /* nothing to check */
  51. default: