summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBastian Krause <bst@pengutronix.de>2021-06-15 12:49:53 +0200
committerBastian Krause <bst@pengutronix.de>2021-06-15 13:06:22 +0200
commit89490b9b7cea8141f7dd1187ad12f0bff7ee8a57 (patch)
treec9038e4a2db7814f344c5f9c924ba23c78740ce6
parenta422efcf6c4a8cb0e48bdbd59dea949caa9b6bff (diff)
downloadgenimage-89490b9b7cea8141f7dd1187ad12f0bff7ee8a57.tar.gz
genimage-89490b9b7cea8141f7dd1187ad12f0bff7ee8a57.tar.xz
image-android-sparse: use off_t instead of int for lseek return values
On a 64 bit system off_t can hold signed, 64 bit integers. Putting large off_t values in a 32 bit int results in overflows. These overflows trigger the "< 0" check and result in errors. This can be observed on large input images. lseek() returns an off_t, so introduce an off_t to store its return value appropriately. Signed-off-by: Bastian Krause <bst@pengutronix.de>
-rw-r--r--image-android-sparse.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/image-android-sparse.c b/image-android-sparse.c
index 58694b3..d51b9d3 100644
--- a/image-android-sparse.c
+++ b/image-android-sparse.c
@@ -118,6 +118,7 @@ static int android_sparse_generate(struct image *image)
struct extent *extents = NULL;
size_t extent_count, extent, block_count, block;
int in_fd = -1, out_fd = -1, ret;
+ off_t offset;
unsigned int i;
uint32_t *buf, *zeros, crc32 = 0;
struct stat s;
@@ -223,8 +224,8 @@ static int android_sparse_generate(struct image *image)
for (i = 0; i < chunk_header.blocks; ++i)
crc32 = crc32_next(zeros, sparse->block_size, crc32);
}
- ret = lseek(in_fd, extents[extent].start, SEEK_SET);
- if (ret < 0) {
+ offset = lseek(in_fd, extents[extent].start, SEEK_SET);
+ if (offset < 0) {
ret = -errno;
image_error(image, "seek %s: %s\n", infile, strerror(errno));
goto out;
@@ -330,8 +331,8 @@ static int android_sparse_generate(struct image *image)
if (ret < 0)
goto out;
- ret = lseek(out_fd, 0, SEEK_SET);
- if (ret < 0) {
+ offset = lseek(out_fd, 0, SEEK_SET);
+ if (offset < 0) {
ret = -errno;
image_error(image, "seek %s: %s\n", infile, strerror(errno));
goto out;