CVE-2014-2270.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  2. Date: Wed Jan 8 22:22:54 2014 +0000
  3. Last-Update: 2014-03-05
  4. Upstream-Commit:
  5. 447558595a3650db2886cd2f416ad0beba965801
  6. 70c65d2e1841491f59168db1f905e8b14083fb1c
  7. Description:
  8. PR/313: Aaron Reffett: Check properly for exceeding the offset.
  9. .
  10. off by one in out of bounds calculations (Jan Kaluza)
  11. .
  12. CVE-2014-2270
  13. Backport for 5.11: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
  14. --- a/src/softmagic.c
  15. +++ b/src/softmagic.c
  16. @@ -60,6 +60,7 @@
  17. private void cvt_32(union VALUETYPE *, const struct magic *);
  18. private void cvt_64(union VALUETYPE *, const struct magic *);
  19. +#define OFFSET_OOB(n, o, i) ((n) < (o) || (i) > ((n) - (o)))
  20. /*
  21. * softmagic - lookup one file in parsed, in-memory copy of database
  22. * Passed the name and FILE * of one file to be typed.
  23. @@ -1080,7 +1081,7 @@
  24. }
  25. switch (m->in_type) {
  26. case FILE_BYTE:
  27. - if (nbytes < (offset + 1))
  28. + if (OFFSET_OOB(nbytes, offset, 1))
  29. return 0;
  30. if (off) {
  31. switch (m->in_op & FILE_OPS_MASK) {
  32. @@ -1115,7 +1116,7 @@
  33. offset = ~offset;
  34. break;
  35. case FILE_BESHORT:
  36. - if (nbytes < (offset + 2))
  37. + if (OFFSET_OOB(nbytes, offset, 2))
  38. return 0;
  39. if (off) {
  40. switch (m->in_op & FILE_OPS_MASK) {
  41. @@ -1167,7 +1168,7 @@
  42. offset = ~offset;
  43. break;
  44. case FILE_LESHORT:
  45. - if (nbytes < (offset + 2))
  46. + if (OFFSET_OOB(nbytes, offset, 2))
  47. return 0;
  48. if (off) {
  49. switch (m->in_op & FILE_OPS_MASK) {
  50. @@ -1219,7 +1220,7 @@
  51. offset = ~offset;
  52. break;
  53. case FILE_SHORT:
  54. - if (nbytes < (offset + 2))
  55. + if (OFFSET_OOB(nbytes, offset, 2))
  56. return 0;
  57. if (off) {
  58. switch (m->in_op & FILE_OPS_MASK) {
  59. @@ -1256,7 +1257,7 @@
  60. break;
  61. case FILE_BELONG:
  62. case FILE_BEID3:
  63. - if (nbytes < (offset + 4))
  64. + if (OFFSET_OOB(nbytes, offset, 4))
  65. return 0;
  66. if (off) {
  67. switch (m->in_op & FILE_OPS_MASK) {
  68. @@ -1327,7 +1328,7 @@
  69. break;
  70. case FILE_LELONG:
  71. case FILE_LEID3:
  72. - if (nbytes < (offset + 4))
  73. + if (OFFSET_OOB(nbytes, offset, 4))
  74. return 0;
  75. if (off) {
  76. switch (m->in_op & FILE_OPS_MASK) {
  77. @@ -1397,7 +1398,7 @@
  78. offset = ~offset;
  79. break;
  80. case FILE_MELONG:
  81. - if (nbytes < (offset + 4))
  82. + if (OFFSET_OOB(nbytes, offset, 4))
  83. return 0;
  84. if (off) {
  85. switch (m->in_op & FILE_OPS_MASK) {
  86. @@ -1467,7 +1468,7 @@
  87. offset = ~offset;
  88. break;
  89. case FILE_LONG:
  90. - if (nbytes < (offset + 4))
  91. + if (OFFSET_OOB(nbytes, offset, 4))
  92. return 0;
  93. if (off) {
  94. switch (m->in_op & FILE_OPS_MASK) {
  95. @@ -1534,14 +1535,14 @@
  96. /* Verify we have enough data to match magic type */
  97. switch (m->type) {
  98. case FILE_BYTE:
  99. - if (nbytes < (offset + 1)) /* should alway be true */
  100. + if (OFFSET_OOB(nbytes, offset, 1))
  101. return 0;
  102. break;
  103. case FILE_SHORT:
  104. case FILE_BESHORT:
  105. case FILE_LESHORT:
  106. - if (nbytes < (offset + 2))
  107. + if (OFFSET_OOB(nbytes, offset, 2))
  108. return 0;
  109. break;
  110. @@ -1560,26 +1561,26 @@
  111. case FILE_FLOAT:
  112. case FILE_BEFLOAT:
  113. case FILE_LEFLOAT:
  114. - if (nbytes < (offset + 4))
  115. + if (OFFSET_OOB(nbytes, offset, 4))
  116. return 0;
  117. break;
  118. case FILE_DOUBLE:
  119. case FILE_BEDOUBLE:
  120. case FILE_LEDOUBLE:
  121. - if (nbytes < (offset + 8))
  122. + if (OFFSET_OOB(nbytes, offset, 8))
  123. return 0;
  124. break;
  125. case FILE_STRING:
  126. case FILE_PSTRING:
  127. case FILE_SEARCH:
  128. - if (nbytes < (offset + m->vallen))
  129. + if (OFFSET_OOB(nbytes, offset, m->vallen))
  130. return 0;
  131. break;
  132. case FILE_REGEX:
  133. - if (nbytes < offset)
  134. + if (OFFSET_OOB(nbytes, offset, 0))
  135. return 0;
  136. break;
  137. @@ -1589,7 +1590,7 @@
  138. if ((ms->flags & (MAGIC_MIME|MAGIC_APPLE)) == 0 &&
  139. file_printf(ms, "%s", m->desc) == -1)
  140. return -1;
  141. - if (nbytes < offset)
  142. + if (OFFSET_OOB(nbytes, offset, 0))
  143. return 0;
  144. return file_softmagic(ms, s + offset, nbytes - offset,
  145. recursion_level, BINTEST, text);