From: Ian Lance Taylor Date: Fri, 18 Jan 2019 17:13:59 +0000 (+0000) Subject: re PR libbacktrace/88890 (libbacktrace on 32-bit system with _FILE_OFFSET_BITS =... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8b248c17bd9999eb3adb585b0789595bada43e8c;p=gcc.git re PR libbacktrace/88890 (libbacktrace on 32-bit system with _FILE_OFFSET_BITS == 64) PR libbacktrace/88890 * mmapio.c (backtrace_get_view): Change size parameter to uint64_t. Check that value fits in size_t. * read.c (backtrace_get_view): Likewise. * internal.h (backtrace_get_view): Update declaration. * elf.c (elf_add): Pass shstrhdr->sh_size to backtrace_get_view. From-SVN: r268082 --- diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 54c4b79d623..cf44db69e2d 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,12 @@ +2019-01-18 Ian Lance Taylor + + PR libbacktrace/88890 + * mmapio.c (backtrace_get_view): Change size parameter to + uint64_t. Check that value fits in size_t. + * read.c (backtrace_get_view): Likewise. + * internal.h (backtrace_get_view): Update declaration. + * elf.c (elf_add): Pass shstrhdr->sh_size to backtrace_get_view. + 2019-01-17 Tom de Vries PR libbacktrace/82857 diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 87e7b0d361d..01cf6f9cff7 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -2813,7 +2813,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor, shstr_size = shstrhdr->sh_size; shstr_off = shstrhdr->sh_offset; - if (!backtrace_get_view (state, descriptor, shstr_off, shstr_size, + if (!backtrace_get_view (state, descriptor, shstr_off, shstrhdr->sh_size, error_callback, data, &names_view)) goto fail; names_view_valid = 1; diff --git a/libbacktrace/internal.h b/libbacktrace/internal.h index e8389779322..065b9535e8b 100644 --- a/libbacktrace/internal.h +++ b/libbacktrace/internal.h @@ -179,7 +179,7 @@ struct backtrace_view /* Create a view of SIZE bytes from DESCRIPTOR at OFFSET. Store the result in *VIEW. Returns 1 on success, 0 on error. */ extern int backtrace_get_view (struct backtrace_state *state, int descriptor, - off_t offset, size_t size, + off_t offset, uint64_t size, backtrace_error_callback error_callback, void *data, struct backtrace_view *view); diff --git a/libbacktrace/mmapio.c b/libbacktrace/mmapio.c index a87eb8f2c36..b188a43a4f2 100644 --- a/libbacktrace/mmapio.c +++ b/libbacktrace/mmapio.c @@ -51,7 +51,7 @@ POSSIBILITY OF SUCH DAMAGE. */ int backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED, - int descriptor, off_t offset, size_t size, + int descriptor, off_t offset, uint64_t size, backtrace_error_callback error_callback, void *data, struct backtrace_view *view) { @@ -60,6 +60,12 @@ backtrace_get_view (struct backtrace_state *state ATTRIBUTE_UNUSED, off_t pageoff; void *map; + if ((uint64_t) (size_t) size != size) + { + error_callback (data, "file size too large", 0); + return 0; + } + pagesize = getpagesize (); inpage = offset % pagesize; pageoff = offset - inpage; diff --git a/libbacktrace/read.c b/libbacktrace/read.c index 010f8f26148..eb485261022 100644 --- a/libbacktrace/read.c +++ b/libbacktrace/read.c @@ -46,12 +46,18 @@ POSSIBILITY OF SUCH DAMAGE. */ int backtrace_get_view (struct backtrace_state *state, int descriptor, - off_t offset, size_t size, + off_t offset, uint64_t size, backtrace_error_callback error_callback, void *data, struct backtrace_view *view) { ssize_t got; + if ((uint64_t) (size_t) size != size) + { + error_callback (data, "file size too large", 0); + return 0; + } + if (lseek (descriptor, offset, SEEK_SET) < 0) { error_callback (data, "lseek", errno);