diff mbox series

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

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

Commit Message

Stefano Babic Oct. 30, 2024, 10:15 a.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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

--
2.34.1
diff mbox series

Patch

diff --git a/handlers/handler_helpers.c b/handlers/handler_helpers.c
index 5861690a..a09c2fe4 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;
+	const char *tmp = buf;

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