aboutsummaryrefslogtreecommitdiffstats
path: root/updater/blockimg.c
diff options
context:
space:
mode:
authorAndrew Boie <andrew.p.boie@intel.com>2014-09-03 12:41:06 -0700
committerDoug Zongker <dougz@google.com>2014-09-04 07:54:17 -0700
commit8328922ff040280007da0aaaf8b567581231d5ed (patch)
tree8cceb71b4652a90c97ad51f84a45b6c1d580d897 /updater/blockimg.c
parent5f875bf57739bf0b5c2d182173513233bdb71ab8 (diff)
downloadbootable_recovery-8328922ff040280007da0aaaf8b567581231d5ed.zip
bootable_recovery-8328922ff040280007da0aaaf8b567581231d5ed.tar.gz
bootable_recovery-8328922ff040280007da0aaaf8b567581231d5ed.tar.bz2
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 <andrew.p.boie@intel.com>
Diffstat (limited to 'updater/blockimg.c')
-rw-r--r--updater/blockimg.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/updater/blockimg.c b/updater/blockimg.c
index 6d412d5..5c0c3a7 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);