TEMP-0000000-B67840.9.68bd843.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Subject: Only trust sizes of regular files
  2. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  3. Date: Tue Dec 9 02:46:38 2014 +0000
  4. Origin: FILE5_20-47-g68bd843
  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 f6b6824..fd4a19f 100644
  9. --- a/src/readelf.c
  10. +++ b/src/readelf.c
  11. @@ -62,6 +62,7 @@ private uint64_t getu64(int, uint64_t);
  12. #define MAX_PHNUM 128
  13. #define MAX_SHNUM 32768
  14. +#define SIZE_UNKNOWN ((off_t)-1)
  15. private int
  16. toomany(struct magic_set *ms, const char *name, uint16_t num)
  17. @@ -332,7 +333,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
  18. }
  19. off += size;
  20. - if (xph_offset > fsize) {
  21. + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
  22. /* Perhaps warn here */
  23. continue;
  24. }
  25. @@ -963,7 +964,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
  26. stripped = 0;
  27. break;
  28. default:
  29. - if (xsh_offset > fsize) {
  30. + if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) {
  31. /* Perhaps warn here */
  32. continue;
  33. }
  34. @@ -1148,7 +1149,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
  35. shared_libraries = " (uses shared libs)";
  36. break;
  37. default:
  38. - if (xph_offset > fsize) {
  39. + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) {
  40. /* Maybe warn here? */
  41. continue;
  42. }
  43. @@ -1241,7 +1242,10 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf,
  44. file_badread(ms);
  45. return -1;
  46. }
  47. - fsize = st.st_size;
  48. + if (S_ISREG(st.st_mode))
  49. + fsize = st.st_size;
  50. + else
  51. + fsize = SIZE_UNKNOWN;
  52. clazz = buf[EI_CLASS];