Merge "Check an edge case when read(2) returns 0"
This commit is contained in:
@@ -336,6 +336,9 @@ int WriteToPartition(const unsigned char* data, size_t len, const char* target)
|
|||||||
printf("verify read error %s at %zu: %s\n",
|
printf("verify read error %s at %zu: %s\n",
|
||||||
partition, p, strerror(errno));
|
partition, p, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
} else if (read_count == 0) {
|
||||||
|
printf("verify read reached unexpected EOF, %s at %zu\n", partition, p);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (static_cast<size_t>(read_count) < to_read) {
|
if (static_cast<size_t>(read_count) < to_read) {
|
||||||
printf("short verify read %s at %zu: %zd %zu %s\n",
|
printf("short verify read %s at %zu: %zd %zu %s\n",
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <android-base/file.h>
|
||||||
|
|
||||||
#include "fuse_sideload.h"
|
#include "fuse_sideload.h"
|
||||||
|
|
||||||
struct file_data {
|
struct file_data {
|
||||||
@@ -41,14 +43,9 @@ static int read_block_file(void* cookie, uint32_t block, uint8_t* buffer, uint32
|
|||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fetch_size > 0) {
|
if (!android::base::ReadFully(fd->fd, buffer, fetch_size)) {
|
||||||
ssize_t r = TEMP_FAILURE_RETRY(read(fd->fd, buffer, fetch_size));
|
fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno));
|
||||||
if (r == -1) {
|
return -EIO;
|
||||||
fprintf(stderr, "read on sdcard failed: %s\n", strerror(errno));
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
fetch_size -= r;
|
|
||||||
buffer += r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ static int read_all(int fd, uint8_t* data, size_t size) {
|
|||||||
failure_type = kFreadFailure;
|
failure_type = kFreadFailure;
|
||||||
fprintf(stderr, "read failed: %s\n", strerror(errno));
|
fprintf(stderr, "read failed: %s\n", strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
|
} else if (r == 0) {
|
||||||
|
failure_type = kFreadFailure;
|
||||||
|
fprintf(stderr, "read reached unexpected EOF.\n");
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
so_far += r;
|
so_far += r;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user