[PATCH 1/2] image-sparse: change retlen to size_t

Steffen Trumtrar s.trumtrar at pengutronix.de
Mon Jan 11 05:32:04 EST 2021


retlen can potentially overflow. Also, write_full() in
fastboot_handle_sparse() expects size_t anyway.

Signed-off-by: Steffen Trumtrar <s.trumtrar at pengutronix.de>
---
 common/fastboot.c      | 2 +-
 include/image-sparse.h | 2 +-
 lib/image-sparse.c     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/common/fastboot.c b/common/fastboot.c
index 1b6dc28d8e..40b92d9982 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -566,7 +566,7 @@ static int fastboot_handle_sparse(struct fastboot *fb,
 	}
 
 	while (1) {
-		int retlen;
+		size_t retlen;
 		loff_t pos;
 
 		ret = sparse_image_read(sparse, buf, &pos, bufsiz, &retlen);
diff --git a/include/image-sparse.h b/include/image-sparse.h
index 29242f4fd5..6bff844411 100644
--- a/include/image-sparse.h
+++ b/include/image-sparse.h
@@ -60,7 +60,7 @@ struct sparse_image_ctx;
 
 struct sparse_image_ctx *sparse_image_open(const char *path);
 int sparse_image_read(struct sparse_image_ctx *si, void *buf,
-		      loff_t *pos, size_t len, int *retlen);
+		      loff_t *pos, size_t len, size_t *retlen);
 void sparse_image_close(struct sparse_image_ctx *si);
 loff_t sparse_image_size(struct sparse_image_ctx *si);
 
diff --git a/lib/image-sparse.c b/lib/image-sparse.c
index 0c31742ab6..8e7a52fd71 100644
--- a/lib/image-sparse.c
+++ b/lib/image-sparse.c
@@ -190,7 +190,7 @@ out:
 }
 
 int sparse_image_read(struct sparse_image_ctx *si, void *buf, loff_t *pos,
-		      size_t len, int *retlen)
+		      size_t len, size_t *retlen)
 {
 	size_t now;
 	int ret, i;
-- 
2.20.1




More information about the barebox mailing list