cherry-pick.FILE5_30-29-g76c2d4ae.several-fixes-in-cdf-parser.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Subject: [ Several fixes in the cdf parser ]
  2. Origin: FILE5_30-29-g76c2d4ae
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Mon Mar 27 21:34:32 2017 +0000
  5. - Check the stream offset for sh.sh_len to fit within the stream
  6. - Fix wrong test (use o4 instead of slen for offset).
  7. - Use left variable to keep track of how many bytes are left.
  8. --- a/src/cdf.c
  9. +++ b/src/cdf.c
  10. @@ -891,7 +891,7 @@
  11. int64_t s64;
  12. uint64_t u64;
  13. cdf_timestamp_t tp;
  14. - size_t i, o4, nelements, j, slen;
  15. + size_t i, o4, nelements, j, slen, left;
  16. cdf_property_info_t *inp;
  17. if (offs > UINT32_MAX / 4) {
  18. @@ -907,6 +907,10 @@
  19. errno = EFTYPE;
  20. goto out;
  21. }
  22. +
  23. + if (cdf_check_stream_offset(sst, h, shp, sh.sh_len, __LINE__) == -1)
  24. + goto out;
  25. +
  26. sh.sh_properties = CDF_TOLE4(shp->sh_properties);
  27. if (sh.sh_properties > CDF_PROP_LIMIT)
  28. goto out;
  29. @@ -940,6 +944,7 @@
  30. nelements = 1;
  31. slen = 1;
  32. }
  33. + left = CAST(size_t, e - q);
  34. o4 = slen * sizeof(uint32_t);
  35. if (inp[i].pi_type & (CDF_ARRAY|CDF_BYREF|CDF_RESERVED))
  36. goto unknown;
  37. @@ -1008,12 +1013,12 @@
  38. {
  39. uint32_t l;
  40. - if (q + slen + sizeof(uint32_t) >= e)
  41. + if (o4 + sizeof(uint32_t) > left)
  42. goto out;
  43. l = CDF_GETUINT32(q, slen);
  44. o4 += sizeof(uint32_t);
  45. - if (o4 + l > CAST(size_t, e - q))
  46. + if (o4 + l > left)
  47. goto out;
  48. inp[i].pi_str.s_len = l;
  49. @@ -1021,8 +1026,8 @@
  50. CAST(const void *, &q[o4]));
  51. DPRINTF(("o=%zu l=%d(%" SIZE_T_FORMAT
  52. - "u), t=%td s=%s\n", o4, l,
  53. - CDF_ROUND(l, sizeof(l)), e - q,
  54. + "u), t=%zu s=%s\n", o4, l,
  55. + CDF_ROUND(l, sizeof(l)), left,
  56. inp[i].pi_str.s_buf));
  57. if (l & 1)