[lxc-devel] [lxc/master] file_utils: fix config file parsing

brauner on Github lxc-bot at linuxcontainers.org
Tue Nov 17 21:35:45 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 538 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201117/3241ab99/attachment.bin>
-------------- next part --------------
From 7d84e2cd65e120146001fa19127f61af0e0d7306 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 17 Nov 2020 22:34:05 +0100
Subject: [PATCH] file_utils: fix config file parsing

We accidently used the "bytes_to_write" variable after we've written all the
bytes at which point it is guaranteed to be 0. Let's use the "bytes_read"
variable instead.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/file_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c
index 3b4bffb399..a8d9aaf304 100644
--- a/src/lxc/file_utils.c
+++ b/src/lxc/file_utils.c
@@ -399,6 +399,7 @@ ssize_t __fd_to_fd(int from, int to)
 			break;
 
 		bytes_to_write = (size_t)bytes_read;
+		total_bytes += bytes_read;
 		do {
 			ssize_t bytes_written;
 
@@ -409,7 +410,6 @@ ssize_t __fd_to_fd(int from, int to)
 			bytes_to_write -= bytes_written;
 			p += bytes_written;
 		} while (bytes_to_write > 0);
-		total_bytes += bytes_to_write;
 	}
 
 	return total_bytes;


More information about the lxc-devel mailing list