From patchwork Thu Jan 21 18:42:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 60102 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp178536lbb; Thu, 21 Jan 2016 10:45:54 -0800 (PST) X-Received: by 10.55.79.69 with SMTP id d66mr53947354qkb.76.1453401954846; Thu, 21 Jan 2016 10:45:54 -0800 (PST) Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id 130si2584436qhw.52.2016.01.21.10.45.53 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 21 Jan 2016 10:45:54 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u0LIhS5r031128; Thu, 21 Jan 2016 13:43:28 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u0LIh6jk013950 for ; Thu, 21 Jan 2016 13:43:06 -0500 Received: from colepc.redhat.com (ovpn-113-198.phx2.redhat.com [10.3.113.198]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0LIh4Yh032379; Thu, 21 Jan 2016 13:43:05 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 21 Jan 2016 13:42:58 -0500 Message-Id: <55fddef24ef0ce6a7f4b25a3ac5314ccf98f9ec3.1453401727.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] lxc: fuse: Fix /proc/meminfo size calculation X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com 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 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 86c0d10..ffa6889 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -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);