aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-18 17:13:59 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-01-18 17:13:59 +0000
commit8b248c17bd9999eb3adb585b0789595bada43e8c (patch)
tree763e0966d741405f3d063a4c83449045813900b5
parent89ce81fbe13dc554d489d9f00f92f85164b185d6 (diff)
downloadgcc-8b248c17bd9999eb3adb585b0789595bada43e8c.zip
gcc-8b248c17bd9999eb3adb585b0789595bada43e8c.tar.gz
gcc-8b248c17bd9999eb3adb585b0789595bada43e8c.tar.bz2
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
-rw-r--r--libbacktrace/ChangeLog9
-rw-r--r--libbacktrace/elf.c2
-rw-r--r--libbacktrace/internal.h2
-rw-r--r--libbacktrace/mmapio.c8
-rw-r--r--libbacktrace/read.c8
5 files changed, 25 insertions, 4 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog
index 54c4b79..cf44db6 100644
--- a/libbacktrace/ChangeLog
+++ b/libbacktrace/ChangeLog
@@ -1,3 +1,12 @@
+2019-01-18 Ian Lance Taylor <iant@golang.org>
+
+ 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 <tdevries@suse.de>
PR libbacktrace/82857
diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c
index 87e7b0d..01cf6f9 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 e838977..065b953 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 a87eb8f..b188a43 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 010f8f2..eb48526 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);