]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc: fuse: Fix /proc/meminfo size calculation
authorCole Robinson <crobinso@redhat.com>
Thu, 21 Jan 2016 18:14:54 +0000 (13:14 -0500)
committerCole Robinson <crobinso@redhat.com>
Fri, 22 Jan 2016 13:32:00 +0000 (08:32 -0500)
We virtualize bits of /proc/meminfo by replacing host values with
values specific to the container.

However for calculating the final size of the returned data, we are
using the size of the original file and not the altered copy, which
could give garbelled output.

src/lxc/lxc_fuse.c

index 86c0d107d8472d7a4e0d164cf947078c7e7a898d..ffa688936550c3f7edb13f26abba325ac84088ee 100644 (file)
@@ -131,7 +131,6 @@ static int lxcProcHostRead(char *path, char *buf, size_t size, off_t offset)
 static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
                               char *buf, size_t size, off_t offset)
 {
-    int copied = 0;
     int res;
     FILE *fd = NULL;
     char *line = NULL;
@@ -159,7 +158,7 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
     }
 
     res = -1;
-    while (copied < size && getline(&line, &n, fd) > 0) {
+    while (getline(&line, &n, fd) > 0) {
         char *ptr = strchr(line, ':');
         if (!ptr)
             continue;
@@ -219,13 +218,11 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def,
             res = -errno;
             goto cleanup;
         }
-
-        copied += strlen(line);
-        if (copied > size)
-            copied = size;
     }
-    res = copied;
-    memcpy(buf, virBufferCurrentContent(new_meminfo), copied);
+    res = strlen(virBufferCurrentContent(new_meminfo));
+    if (res > size)
+        res = size;
+    memcpy(buf, virBufferCurrentContent(new_meminfo), res);
 
  cleanup:
     VIR_FREE(line);