From 8328922ff040280007da0aaaf8b567581231d5ed Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Wed, 3 Sep 2014 12:41:06 -0700 Subject: use lseek64 instead of lseek Otherwise, overflow problems can occur with images larger than 2G since the offsets will overflow a 32-bit off_t. Change-Id: I05951a38ebeae83ad2cb938594e8d8adb323e2aa Signed-off-by: Andrew Boie --- updater/blockimg.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/updater/blockimg.c b/updater/blockimg.c index 6d412d5d5..5c0c3a727 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.c @@ -106,12 +106,12 @@ static void writeblock(int fd, const uint8_t* data, size_t size) { } } -static void check_lseek(int fd, off_t offset, int whence) { +static void check_lseek(int fd, off64_t offset, int whence) { while (true) { - off_t ret = lseek(fd, offset, whence); + off64_t ret = lseek64(fd, offset, whence); if (ret < 0) { if (errno != EINTR) { - fprintf(stderr, "lseek failed: %s\n", strerror(errno)); + fprintf(stderr, "lseek64 failed: %s\n", strerror(errno)); exit(1); } } else { @@ -165,7 +165,7 @@ static ssize_t RangeSinkWrite(const uint8_t* data, ssize_t size, void* token) { ++rss->p_block; if (rss->p_block < rss->tgt->count) { rss->p_remain = (rss->tgt->pos[rss->p_block*2+1] - rss->tgt->pos[rss->p_block*2]) * BLOCKSIZE; - check_lseek(rss->fd, rss->tgt->pos[rss->p_block*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(rss->fd, (off64_t)rss->tgt->pos[rss->p_block*2] * BLOCKSIZE, SEEK_SET); } else { // we can't write any more; return how many bytes have // been written so far. @@ -414,7 +414,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] allocate(src->size * BLOCKSIZE, &buffer, &buffer_alloc); size_t p = 0; for (i = 0; i < src->count; ++i) { - check_lseek(fd, src->pos[i*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)src->pos[i*2] * BLOCKSIZE, SEEK_SET); size_t sz = (src->pos[i*2+1] - src->pos[i*2]) * BLOCKSIZE; readblock(fd, buffer+p, sz); p += sz; @@ -422,7 +422,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] p = 0; for (i = 0; i < tgt->count; ++i) { - check_lseek(fd, tgt->pos[i*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)tgt->pos[i*2] * BLOCKSIZE, SEEK_SET); size_t sz = (tgt->pos[i*2+1] - tgt->pos[i*2]) * BLOCKSIZE; writeblock(fd, buffer+p, sz); p += sz; @@ -445,7 +445,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] allocate(BLOCKSIZE, &buffer, &buffer_alloc); memset(buffer, 0, BLOCKSIZE); for (i = 0; i < tgt->count; ++i) { - check_lseek(fd, tgt->pos[i*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)tgt->pos[i*2] * BLOCKSIZE, SEEK_SET); for (j = tgt->pos[i*2]; j < tgt->pos[i*2+1]; ++j) { writeblock(fd, buffer, BLOCKSIZE); } @@ -470,7 +470,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] rss.tgt = tgt; rss.p_block = 0; rss.p_remain = (tgt->pos[1] - tgt->pos[0]) * BLOCKSIZE; - check_lseek(fd, tgt->pos[0] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)tgt->pos[0] * BLOCKSIZE, SEEK_SET); pthread_mutex_lock(&nti.mu); nti.rss = &rss; @@ -504,7 +504,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] allocate(src->size * BLOCKSIZE, &buffer, &buffer_alloc); size_t p = 0; for (i = 0; i < src->count; ++i) { - check_lseek(fd, src->pos[i*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)src->pos[i*2] * BLOCKSIZE, SEEK_SET); size_t sz = (src->pos[i*2+1] - src->pos[i*2]) * BLOCKSIZE; readblock(fd, buffer+p, sz); p += sz; @@ -520,7 +520,7 @@ Value* BlockImageUpdateFn(const char* name, State* state, int argc, Expr* argv[] rss.tgt = tgt; rss.p_block = 0; rss.p_remain = (tgt->pos[1] - tgt->pos[0]) * BLOCKSIZE; - check_lseek(fd, tgt->pos[0] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)tgt->pos[0] * BLOCKSIZE, SEEK_SET); if (style[0] == 'i') { // imgdiff ApplyImagePatch(buffer, src->size * BLOCKSIZE, @@ -620,7 +620,7 @@ Value* RangeSha1Fn(const char* name, State* state, int argc, Expr* argv[]) { int i, j; for (i = 0; i < rs->count; ++i) { - check_lseek(fd, rs->pos[i*2] * (off_t)BLOCKSIZE, SEEK_SET); + check_lseek(fd, (off64_t)rs->pos[i*2] * BLOCKSIZE, SEEK_SET); for (j = rs->pos[i*2]; j < rs->pos[i*2+1]; ++j) { readblock(fd, buffer, BLOCKSIZE); SHA_update(&ctx, buffer, BLOCKSIZE); -- cgit v1.2.3 From f7bb09dae8d7c89130648ef2aca7025860b6d801 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Thu, 4 Sep 2014 08:10:32 -0700 Subject: fix comment in blockimg updater code The comment for the DEBUG_ERASE setting is exactly backwards. Change-Id: I98ab5828365894217fc78976817a131e7d22d5c1 --- updater/blockimg.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/updater/blockimg.c b/updater/blockimg.c index 6d412d5d5..555230dd3 100644 --- a/updater/blockimg.c +++ b/updater/blockimg.c @@ -37,9 +37,9 @@ #define BLOCKSIZE 4096 -// Set this to 1 to interpret 'erase' transfers to mean do a -// BLKDISCARD ioctl. Set to 0 to interpret erase to mean fill the -// region with zeroes. +// Set this to 0 to interpret 'erase' transfers to mean do a +// BLKDISCARD ioctl (the normal behavior). Set to 1 to interpret +// erase to mean fill the region with zeroes. #define DEBUG_ERASE 0 #ifndef BLKDISCARD -- cgit v1.2.3 From 574443d8956802f35347cac7fae7eb16240e3c16 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Fri, 5 Sep 2014 08:22:12 -0700 Subject: create block map for all update packages on /data Always create the block map for packages on /data; don't only look at the encryptable/encrypted flags. Bug: 17395453 Change-Id: Iaa7643a32898328277841e324305b9419a9e071c --- uncrypt/uncrypt.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/uncrypt/uncrypt.c b/uncrypt/uncrypt.c index 07e5ae665..189fa57e1 100644 --- a/uncrypt/uncrypt.c +++ b/uncrypt/uncrypt.c @@ -160,8 +160,6 @@ char* parse_recovery_command_file() int count = 0; char temp[1024]; - - FILE* f = fopen(RECOVERY_COMMAND_FILE, "r"); if (f == NULL) { return NULL; @@ -405,16 +403,15 @@ int main(int argc, char** argv) ALOGI("encryptable: %s\n", encryptable ? "yes" : "no"); ALOGI(" encrypted: %s\n", encrypted ? "yes" : "no"); - if (!encryptable) { - // If the file is on a filesystem that doesn't support - // encryption (eg, /cache), then leave it alone. - // - // TODO: change this to be !encrypted -- if the file is on - // /data but /data isn't encrypted, we don't need to use the - // block map mechanism. We do for now so as to get more - // testing of it (since most dogfood devices aren't - // encrypted). - + // Recovery supports installing packages from 3 paths: /cache, + // /data, and /sdcard. (On a particular device, other locations + // may work, but those are three we actually expect.) + // + // On /data we want to convert the file to a block map so that we + // can read the package without mounting the partition. On /cache + // and /sdcard we leave the file alone. + if (strncmp(path, "/data/", 6) != 0) { + // path does not start with "/data/"; leave it alone. unlink(RECOVERY_COMMAND_FILE_TMP); } else { ALOGI("writing block map %s", map_file); -- cgit v1.2.3