TEMP-0000000-B67840.11.445c8fb.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Subject: Bail out on partial reads, from Alexander Cherepanov
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Tue Dec 16 20:53:05 2014 +0000
  4. Origin: FILE5_21-10-g445c8fb
  5. Last-Update: 2015-01-05
  6. (prequisite for TEMP-0000000-B67840)
  7. diff --git a/src/readelf.c b/src/readelf.c
  8. index fd4a19f..544c22b 100644
  9. --- a/src/readelf.c
  10. +++ b/src/readelf.c
  11. @@ -327,7 +327,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
  12. * Loop through all the program headers.
  13. */
  14. for ( ; num; num--) {
  15. - if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
  16. + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
  17. file_badread(ms);
  18. return -1;
  19. }
  20. @@ -930,6 +930,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
  21. uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
  22. uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
  23. char name[50];
  24. + ssize_t namesize;
  25. if (size != xsh_sizeof) {
  26. if (file_printf(ms, ", corrupted section header size") == -1)
  27. @@ -949,7 +950,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
  28. stripped = 0;
  29. for ( ; num; num--) {
  30. - if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
  31. + if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
  32. file_badread(ms);
  33. return -1;
  34. }
  35. @@ -979,7 +980,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
  36. " for note");
  37. return -1;
  38. }
  39. - if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
  40. + if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
  41. file_badread(ms);
  42. free(nbuf);
  43. return -1;
  44. @@ -1133,7 +1134,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
  45. }
  46. for ( ; num; num--) {
  47. - if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
  48. + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
  49. file_badread(ms);
  50. return -1;
  51. }