X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=libbacktrace%2Fread.c;h=1a6052bf61396e3786dd7810854f462635cadea2;hb=cb84595d3f406fb466c68e5ff6661dd8ee4a4e9c;hp=c618a50b36d3fd6f270e87debf2d83740fd28941;hpb=afeba5cb1dd656d3613691caee1427761dbff358;p=gcc.git diff --git a/libbacktrace/read.c b/libbacktrace/read.c index c618a50b36d..1a6052bf613 100644 --- a/libbacktrace/read.c +++ b/libbacktrace/read.c @@ -1,5 +1,5 @@ /* read.c -- File views without mmap. - Copyright (C) 2012-2014 Free Software Foundation, Inc. + Copyright (C) 2012-2020 Free Software Foundation, Inc. Written by Ian Lance Taylor, Google. Redistribution and use in source and binary forms, with or without @@ -7,13 +7,13 @@ modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the - distribution. - + distribution. + (3) The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. @@ -46,11 +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; + uint64_t got; + ssize_t r; + + if ((uint64_t) (size_t) size != size) + { + error_callback (data, "file size too large", 0); + return 0; + } if (lseek (descriptor, offset, SEEK_SET) < 0) { @@ -64,15 +71,22 @@ backtrace_get_view (struct backtrace_state *state, int descriptor, view->data = view->base; view->len = size; - got = read (descriptor, view->base, size); - if (got < 0) + got = 0; + while (got < size) { - error_callback (data, "read", errno); - free (view->base); - return 0; + r = read (descriptor, view->base, size - got); + if (r < 0) + { + error_callback (data, "read", errno); + free (view->base); + return 0; + } + if (r == 0) + break; + got += (uint64_t) r; } - if ((size_t) got < size) + if (got < size) { error_callback (data, "file too short", 0); free (view->base);