diff mbox series

[V2,08/10] BUG: fix data transfer in callback used by docker

Message ID 20241030163957.2822282-9-stefano.babic@swupdate.org
State Accepted
Headers show
Series Introduce BTRFS Snapshot Handler | expand

Commit Message

Stefano Babic Oct. 30, 2024, 4:39 p.m. UTC
The callback has severe bugs and it works because the write() can be
done in a single step. Loop is buggy, and it does not work if multiple
write are required to transfer the data.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 handlers/handler_helpers.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

--
2.34.1
diff mbox series

Patch

diff --git a/handlers/handler_helpers.c b/handlers/handler_helpers.c
index 5861690a..77467d39 100644
--- a/handlers/handler_helpers.c
+++ b/handlers/handler_helpers.c
@@ -28,12 +28,12 @@ 
 int handler_transfer_data(void *data, const void *buf, size_t len)
 {
 	struct hnd_load_priv *priv = (struct hnd_load_priv *)data;
-	ssize_t written;
-	unsigned int nbytes = len;
-	const void *tmp = buf;
+	size_t nbytes = len;
+	const char *tmp = buf;

-	while (nbytes) {
-		written = write(priv->fifo[FIFO_HND_WRITE], buf, len);
+	while (nbytes > 0) {
+		ssize_t written;
+		written = write(priv->fifo[FIFO_HND_WRITE], tmp, nbytes);
 		if (written < 0) {
 			ERROR ("Cannot write to fifo");
 			return -EFAULT;