aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTianjie Xu2016-08-31 20:06:33 -0500
committerTianjie Xu2016-08-31 21:11:41 -0500
commit71e182bc3879a53f04a50de9d25c333163cb7c76 (patch)
tree4f116fad73bb81476238deb9a70313f54cd68246 /fuse_sdcard_provider.cpp
parent818394869d36b9db1bf4984585a062d4bb91310f (diff)
downloadplatform-bootable-recovery-71e182bc3879a53f04a50de9d25c333163cb7c76.tar.gz
platform-bootable-recovery-71e182bc3879a53f04a50de9d25c333163cb7c76.tar.xz
platform-bootable-recovery-71e182bc3879a53f04a50de9d25c333163cb7c76.zip
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
Diffstat (limited to 'fuse_sdcard_provider.cpp')
-rw-r--r--fuse_sdcard_provider.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/fuse_sdcard_provider.cpp b/fuse_sdcard_provider.cpp
index df963127..b0ecf96b 100644
--- a/fuse_sdcard_provider.cpp
+++ b/fuse_sdcard_provider.cpp
@@ -23,6 +23,8 @@
23#include <unistd.h> 23#include <unistd.h>
24#include <fcntl.h> 24#include <fcntl.h>
25 25
26#include <android-base/file.h>
27
26#include "fuse_sideload.h" 28#include "fuse_sideload.h"
27 29
28struct file_data { 30struct file_data {
@@ -41,14 +43,9 @@ static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32
41 return -EIO; 43 return -EIO;
42 } 44 }
43 45
44 while (fetch_size > 0) { 46 if (!android::base::ReadFully(fd->fd, buffer, fetch_size)) {
45 ssize_t r = TEMP_FAILURE_RETRY(read(fd->fd, buffer, fetch_size)); 47 fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno));
46 if (r == -1) { 48 return -EIO;
47 fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno));
48 return -EIO;
49 }
50 fetch_size -= r;
51 buffer += r;
52 } 49 }
53 50
54 return 0; 51 return 0;