901-file-elf.dpatch 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh /usr/share/dpatch/dpatch-run
  2. ## 91-file-elf.dpatch by Alessandro Rubini <rubini@gnudd.com>
  3. ##
  4. ## DP: Revert ELF file-reading (closes: #345089).
  5. @DPATCH@
  6. diff -Naur file-4.20.orig/src/readelf.c file-4.20/src/readelf.c
  7. --- file-4.20.orig/src/readelf.c 2007-01-18 05:45:35.000000000 +0000
  8. +++ file-4.20/src/readelf.c 2007-03-27 12:23:14.000000000 +0000
  9. @@ -907,29 +915,30 @@
  10. off_t fsize;
  11. int flags = 0;
  12. - /*
  13. - * If we cannot seek, it must be a pipe, socket or fifo.
  14. - */
  15. - if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
  16. - fd = file_pipe2file(ms, fd, buf, nbytes);
  17. -
  18. - if (fstat(fd, &st) == -1) {
  19. - file_badread(ms);
  20. - return -1;
  21. - }
  22. - fsize = st.st_size;
  23. /*
  24. * ELF executables have multiple section headers in arbitrary
  25. * file locations and thus file(1) cannot determine it from easily.
  26. * Instead we traverse thru all section headers until a symbol table
  27. * one is found or else the binary is stripped.
  28. + * Return immediately if it's not ELF (so we avoid pipe2file unless needed).
  29. */
  30. if (buf[EI_MAG0] != ELFMAG0
  31. || (buf[EI_MAG1] != ELFMAG1 && buf[EI_MAG1] != OLFMAG1)
  32. || buf[EI_MAG2] != ELFMAG2 || buf[EI_MAG3] != ELFMAG3)
  33. return 0;
  34. + /*
  35. + * If we cannot seek, it must be a pipe, socket or fifo.
  36. + */
  37. + if((lseek(fd, (off_t)0, SEEK_SET) == (off_t)-1) && (errno == ESPIPE))
  38. + fd = file_pipe2file(ms, fd, buf, nbytes);
  39. +
  40. + if (fstat(fd, &st) == -1) {
  41. + file_badread(ms);
  42. + return -1;
  43. + }
  44. + fsize = st.st_size;
  45. class = buf[EI_CLASS];