CVE-2014-9653.5.445c8fb.patch 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. Subject: Bail out on partial reads, from Alexander Cherepanov
  2. ID: CVE-2014-9653
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Tue Dec 16 20:53:05 2014 +0000
  5. Origin: FILE5_21-10-g445c8fb
  6. Last-Update: 2015-04-19
  7. --- a/src/readelf.c
  8. +++ b/src/readelf.c
  9. @@ -324,7 +324,7 @@
  10. * Loop through all the program headers.
  11. */
  12. for ( ; num; num--) {
  13. - if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
  14. + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
  15. file_badread(ms);
  16. return -1;
  17. }
  18. @@ -852,6 +852,7 @@
  19. uint64_t cap_hw1 = 0; /* SunOS 5.x hardware capabilites */
  20. uint64_t cap_sf1 = 0; /* SunOS 5.x software capabilites */
  21. char name[50];
  22. + ssize_t namesize;
  23. if (size != xsh_sizeof) {
  24. if (file_printf(ms, ", corrupted section header size") == -1)
  25. @@ -860,7 +861,7 @@
  26. }
  27. /* Read offset of name section to be able to read section names later */
  28. - if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) == -1) {
  29. + if (pread(fd, xsh_addr, xsh_sizeof, off + size * strtab) < (ssize_t)xsh_sizeof) {
  30. file_badread(ms);
  31. return -1;
  32. }
  33. @@ -868,15 +869,15 @@
  34. for ( ; num; num--) {
  35. /* Read the name of this section. */
  36. - if (pread(fd, name, sizeof(name), name_off + xsh_name) == -1) {
  37. + if ((namesize = pread(fd, name, sizeof(name) - 1, name_off + xsh_name)) == -1) {
  38. file_badread(ms);
  39. return -1;
  40. }
  41. - name[sizeof(name) - 1] = '\0';
  42. + name[namesize] = '\0';
  43. if (strcmp(name, ".debug_info") == 0)
  44. stripped = 0;
  45. - if (pread(fd, xsh_addr, xsh_sizeof, off) == -1) {
  46. + if (pread(fd, xsh_addr, xsh_sizeof, off) < (ssize_t)xsh_sizeof) {
  47. file_badread(ms);
  48. return -1;
  49. }
  50. @@ -900,7 +901,7 @@
  51. " for note");
  52. return -1;
  53. }
  54. - if (pread(fd, nbuf, xsh_size, xsh_offset) == -1) {
  55. + if (pread(fd, nbuf, xsh_size, xsh_offset) < (ssize_t)xsh_size) {
  56. file_badread(ms);
  57. free(nbuf);
  58. return -1;
  59. @@ -1056,7 +1057,7 @@
  60. }
  61. for ( ; num; num--) {
  62. - if (pread(fd, xph_addr, xph_sizeof, off) == -1) {
  63. + if (pread(fd, xph_addr, xph_sizeof, off) < (ssize_t)xph_sizeof) {
  64. file_badread(ms);
  65. return -1;
  66. }