cherry-pick.FILE5_34-16-g2f866ff0.better-error-handling-found-by-coverity.patch 589 B

1234567891011121314151617
  1. Subject: Better error handling, found by coverity
  2. Origin: FILE5_34-16-g2f866ff0 <https://github.com/file/file/commit/FILE5_34-16-g2f866ff0>
  3. Upstream-Author: Christos Zoulas <christos@zoulas.com>
  4. Date: Wed Aug 1 10:02:20 2018 +0000
  5. --- a/src/readelf.c
  6. +++ b/src/readelf.c
  7. @@ -891,7 +891,8 @@
  8. offset = get_offset_from_virtaddr(ms, swap, clazz, fd, ph_off, ph_num,
  9. fsize, virtaddr);
  10. - if ((buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) {
  11. + if (offset < 0 ||
  12. + (buflen = pread(fd, buf, CAST(size_t, buflen), offset)) <= 0) {
  13. file_badread(ms);
  14. return 0;
  15. }