summaryrefslogtreecommitdiffstats
path: root/uncrypt
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-28 17:24:24 -0700
committerElliott Hughes <enh@google.com>2015-04-29 21:14:56 -0700
commit2f5feedf1d705b53e5bf90c8b5207dd91f4522f1 (patch)
treee2c357667b0e76e6fa5a43c7a7951c872c373e9c /uncrypt
parentf7466f9f2334b0e9025e1c7ecf65b4d04a246b20 (diff)
downloadbootable_recovery-2f5feedf1d705b53e5bf90c8b5207dd91f4522f1.zip
bootable_recovery-2f5feedf1d705b53e5bf90c8b5207dd91f4522f1.tar.gz
bootable_recovery-2f5feedf1d705b53e5bf90c8b5207dd91f4522f1.tar.bz2
Check all lseek calls succeed.
Also add missing TEMP_FAILURE_RETRYs on read, write, and lseek. Bug: http://b/20625546 Change-Id: I03b198e11c1921b35518ee2dd005a7cfcf4fd94b (cherry picked from commit 7bad7c4646ee8fd8d6e6ed0ffd3ddbb0c1b41a2f)
Diffstat (limited to 'uncrypt')
-rw-r--r--uncrypt/uncrypt.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/uncrypt/uncrypt.c b/uncrypt/uncrypt.c
index aa75210..da035df 100644
--- a/uncrypt/uncrypt.c
+++ b/uncrypt/uncrypt.c
@@ -65,12 +65,15 @@ static struct fstab* fstab = NULL;
static int write_at_offset(unsigned char* buffer, size_t size,
int wfd, off64_t offset)
{
- lseek64(wfd, offset, SEEK_SET);
+ if (TEMP_FAILURE_RETRY(lseek64(wfd, offset, SEEK_SET)) == -1) {
+ ALOGE("error seeking to offset %lld: %s\n", offset, strerror(errno));
+ return -1;
+ }
size_t written = 0;
while (written < size) {
- ssize_t wrote = write(wfd, buffer + written, size - written);
- if (wrote < 0) {
- ALOGE("error writing offset %lld: %s\n", offset, strerror(errno));
+ ssize_t wrote = TEMP_FAILURE_RETRY(write(wfd, buffer + written, size - written));
+ if (wrote == -1) {
+ ALOGE("error writing offset %lld: %s\n", (offset + written), strerror(errno));
return -1;
}
written += wrote;
@@ -275,8 +278,9 @@ int produce_block_map(const char* path, const char* map_file, const char* blk_de
if (encrypted) {
size_t so_far = 0;
while (so_far < sb.st_blksize && pos < sb.st_size) {
- ssize_t this_read = read(fd, buffers[tail] + so_far, sb.st_blksize - so_far);
- if (this_read < 0) {
+ ssize_t this_read =
+ TEMP_FAILURE_RETRY(read(fd, buffers[tail] + so_far, sb.st_blksize - so_far));
+ if (this_read == -1) {
ALOGE("failed to read: %s\n", strerror(errno));
return -1;
}
@@ -340,8 +344,8 @@ void wipe_misc() {
size_t written = 0;
size_t size = sizeof(zeroes);
while (written < size) {
- ssize_t w = write(fd, zeroes, size-written);
- if (w < 0 && errno != EINTR) {
+ ssize_t w = TEMP_FAILURE_RETRY(write(fd, zeroes, size-written));
+ if (w == -1) {
ALOGE("zero write failed: %s\n", strerror(errno));
return;
} else {