From 71e182bc3879a53f04a50de9d25c333163cb7c76 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 31 Aug 2016 18:06:33 -0700 Subject: Check an edge case when read(2) returns 0 We might end up in an infinite loop if read(2) reached EOF unexpectedly. The problematic code in uncrypt mentioned in the bug has been fixed by switching to libbase ReadFully(). So I grepped through the recovery code and fixed some other occurences of the issue. Bug: 31073201 Change-Id: Ib867029158ba23363b8f85d61c25058a635c5a6b --- updater/blockimg.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'updater') diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp index f00bc4bff..0caa1acbd 100644 --- a/updater/blockimg.cpp +++ b/updater/blockimg.cpp @@ -151,6 +151,10 @@ static int read_all(int fd, uint8_t* data, size_t size) { failure_type = kFreadFailure; fprintf(stderr, "read failed: %s\n", strerror(errno)); return -1; + } else if (r == 0) { + failure_type = kFreadFailure; + fprintf(stderr, "read reached unexpected EOF.\n"); + return -1; } so_far += r; } -- cgit v1.2.3