TEMP-0000000-C482B4.59e6383.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. Subject: PR/398: Correctly truncate pascal strings (fixes out of bounds read of 1, 2, or 4 bytes)
  2. ID: TEMP-0000000-C482B4
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Tue Nov 11 17:48:23 2014 +0000
  5. Origin: FILE5_20-21-g59e6383
  6. Last-Update: 2015-01-09
  7. PR/398: Correctly truncate pascal strings (fixes out of bounds read of 1, 2,
  8. or 4 bytes).
  9. --- a/src/softmagic.c
  10. +++ b/src/softmagic.c
  11. @@ -803,14 +803,17 @@
  12. size_t sz = file_pstring_length_size(m);
  13. char *ptr1 = p->s, *ptr2 = ptr1 + sz;
  14. size_t len = file_pstring_get_length(m, ptr1);
  15. - if (len >= sizeof(p->s)) {
  16. + sz = sizeof(p->s) - sz; /* maximum length of string */
  17. + if (len >= sz) {
  18. /*
  19. * The size of the pascal string length (sz)
  20. * is 1, 2, or 4. We need at least 1 byte for NUL
  21. * termination, but we've already truncated the
  22. * string by p->s, so we need to deduct sz.
  23. + * Because we can use one of the bytes of the length
  24. + * after we shifted as NUL termination.
  25. */
  26. - len = sizeof(p->s) - sz;
  27. + len = sz;
  28. }
  29. while (len--)
  30. *ptr1++ = *ptr2++;