diff mbox series

[RFC,6/9] cpio_utils: fill_buffer: fix return value on EOF after short read

Message ID 20240603085602.2351411-7-dominique.martinet@atmark-techno.com
State RFC
Headers show
Series Proof of concept of chunked checksums | expand

Commit Message

Dominique Martinet June 3, 2024, 8:55 a.m. UTC
fill_buffer would return 0 after having filled buffer/updated checksums
if it reaches the end of file (returns 0) after another read.

In practice, this never happens because the caller knows how much to
read, and chunks are smaller than what had been previously written in
the pipe so this is a theorical problem, but because the checksums are
correctly updated until the end this would not be detected if it happens
in practice (the end of the data would just not be fed to the handler),
so this is best fixed.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/cpio_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index b0a97004baf6..382b22c36434 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -73,7 +73,7 @@  static int _fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigne
 			return -EFAULT;
 		}
 		if (len == 0) {
-			return 0;
+			return count;
 		}
 		if (checksum)
 			for (i = 0; i < len; i++)