aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbacktrace/ChangeLog4
-rw-r--r--libbacktrace/read.c22
2 files changed, 19 insertions, 7 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog
index 277d7c0..4b4f574 100644
--- a/libbacktrace/ChangeLog
+++ b/libbacktrace/ChangeLog
@@ -1,5 +1,9 @@
2020-05-09 Ian Lance Taylor <iant@golang.org>
+ * read.c (backtrace_get_view): Support short read.
+
+2020-05-09 Ian Lance Taylor <iant@golang.org>
+
* elf.c (elf_add): If debug sections are very large or far apart,
read them individually rather than as a single view.
diff --git a/libbacktrace/read.c b/libbacktrace/read.c
index 57e4701..1a6052b 100644
--- a/libbacktrace/read.c
+++ b/libbacktrace/read.c
@@ -50,7 +50,8 @@ backtrace_get_view (struct backtrace_state *state, int descriptor,
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)
{
@@ -70,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);