cherry-pick.FILE5_34-2-gedb7f0d6.pr-9-christoph-bield-handle-files-without-program-headers-gracefully.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Subject: PR/9: Christoph Bield: Handle files without program headers gracefully
  2. Origin: FILE5_34-2-gedb7f0d6 <https://github.com/file/file/commit/FILE5_34-2-gedb7f0d6>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Jul 25 06:12:09 2018 +0000
  5. Bug-Debian: https://bugs.debian.org/882310
  6. --- a/src/readelf.c
  7. +++ b/src/readelf.c
  8. @@ -352,6 +352,11 @@
  9. off_t ph_off = off;
  10. int ph_num = num;
  11. + if (num == 0) {
  12. + if (file_printf(ms, ", no program header") == -1)
  13. + return -1;
  14. + return 0;
  15. + }
  16. if (size != xph_sizeof) {
  17. if (file_printf(ms, ", corrupted program header size") == -1)
  18. return -1;
  19. @@ -1278,6 +1283,11 @@
  20. char name[50];
  21. ssize_t namesize;
  22. + if (num == 0) {
  23. + if (file_printf(ms, ", no section header") == -1)
  24. + return -1;
  25. + return 0;
  26. + }
  27. if (size != xsh_sizeof) {
  28. if (file_printf(ms, ", corrupted section header size") == -1)
  29. return -1;
  30. @@ -1549,6 +1559,11 @@
  31. ssize_t bufsize;
  32. size_t offset, align, len;
  33. + if (num == 0) {
  34. + if (file_printf(ms, ", no program header") == -1)
  35. + return -1;
  36. + return 0;
  37. + }
  38. if (size != xph_sizeof) {
  39. if (file_printf(ms, ", corrupted program header size") == -1)
  40. return -1;