The initial check should use real lengths as with modulo a
new required length of eg. 52 would be considered smaller
than an old length of 48 (2 < 48).

To get the 'batches' count 'newlen' must be divided and not
taken modulo BATCH_SIZE. Otherwise '101', which would need a
3rd batch to reach 150, would end up with two (2*50 = 100
bytes) and thereby be truncated instead.

Signed-off-by: Wolfgang Bumiller <w.bumil...@proxmox.com>
---
 cgfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cgfs.c b/cgfs.c
index 0659e9e..681a478 100644
--- a/cgfs.c
+++ b/cgfs.c
@@ -75,9 +75,9 @@ static inline void drop_trailing_newlines(char *s)
 static void dorealloc(char **mem, size_t oldlen, size_t newlen)
 {
        int batches;
-       if (newlen % BATCH_SIZE <= oldlen % BATCH_SIZE)
+       if (newlen <= oldlen)
                return;
-       batches = (newlen % BATCH_SIZE) + 1;
+       batches = (newlen / BATCH_SIZE) + 1;
        if (!*mem) {
                do {
                        *mem = malloc(batches * BATCH_SIZE);
-- 
2.1.4


_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to