Received: from eggs.gnu.org ([2001:4830:134:3::10]:48701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKOKS-0000JI-MA for qemu-devel@nongnu.org; Mon, 03 Mar 2014 03:34:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKOKM-0006JS-ND for qemu-devel@nongnu.org; Mon, 03 Mar 2014 03:34:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59758) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKOKM-0006JO-FN for qemu-devel@nongnu.org; Mon, 03 Mar 2014 03:34:22 -0500 From: Markus Armbruster References: <52EF68CA.9060604@gmail.com> <20140203103429.GB10408@redhat.com> <52EF71DC.3000309@gmail.com> <52F0C8BA.7020709@gmail.com> <20140204110631.GD5632@redhat.com> <52F0CD67.5070601@gmail.com> <87siry3l7t.fsf@linux.vnet.ibm.com> <52F17B5E.1050602@gmail.com> <52FF3182.9090106@gmail.com> <53097D8E.1030803@gmail.com> <87sir850ho.fsf@blackfin.pond.sub.org> <87ha7o3c5x.fsf@blackfin.pond.sub.org> <530FCBAD.10305@gmail.com> <531219CC.4050505@gmail.com> <53121A12.5050105@gmail.com> <53121A4B.70308@gmail.com> <53121A93.8080301@gmail.com> Date: Mon, 03 Mar 2014 09:34:15 +0100 In-Reply-To: <53121A93.8080301@gmail.com> (Chen Gang's message of "Sun, 02 Mar 2014 01:36:19 +0800") Message-ID: <87siqz65q0.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 3/3] hw/9pfs: use g_strdup_printf() instead of PATH_MAX limitation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Chen Gang Cc: "Aneesh Kumar K.V" , aliguori@amazon.com, QEMU Developers Chen Gang writes: > When path is truncated by PATH_MAX limitation, it causes QEMU to access > incorrect file. So use original full path instead of PATH_MAX within > 9pfs (need check/process ENOMEM for related memory allocation). > > The related test: [...] > Signed-off-by: Chen Gang > --- > hw/9pfs/cofs.c | 15 ++- > hw/9pfs/virtio-9p-handle.c | 9 +- > hw/9pfs/virtio-9p-local.c | 285 +++++++++++++++++++++++++++-------------- > hw/9pfs/virtio-9p-posix-acl.c | 52 ++++++-- > hw/9pfs/virtio-9p-xattr-user.c | 27 +++- > hw/9pfs/virtio-9p-xattr.c | 9 +- > hw/9pfs/virtio-9p-xattr.h | 27 +++- > hw/9pfs/virtio-9p.h | 6 +- > 8 files changed, 292 insertions(+), 138 deletions(-) > > diff --git a/hw/9pfs/cofs.c b/hw/9pfs/cofs.c > index 3891050..739bad0 100644 > --- a/hw/9pfs/cofs.c > +++ b/hw/9pfs/cofs.c > @@ -20,18 +20,24 @@ > int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf) > { > int err; > - ssize_t len; > + ssize_t len, maxlen = PATH_MAX; > V9fsState *s = pdu->s; > > if (v9fs_request_cancelled(pdu)) { > return -EINTR; > } > - buf->data = g_malloc(PATH_MAX); > + buf->data = g_malloc(maxlen); > v9fs_path_read_lock(s); > v9fs_co_run_in_worker( > - { > + while (1) { > len = s->ops->readlink(&s->ctx, path, > - buf->data, PATH_MAX - 1); > + buf->data, maxlen - 1); > + if (len == maxlen - 1) { > + g_free(buf->data); > + maxlen *= 2; > + buf->data = g_malloc(maxlen); > + continue; > + } > if (len > -1) { > buf->size = len; > buf->data[len] = 0; err = 0; > } else { > err = -errno; > } > + break; > }); > v9fs_path_unlock(s); > if (err) { Harmless off-by-one: you double the buffer even when the link contents plus terminating null fits the buffer exactly (len == maxlen - 1). I prefer to have the exceptional stuff handled in conditionals, and not the normal stuff, like this: for (;;) { len = s->ops->readlink(&s->ctx, path, buf->data, maxlen); if (len < 0) { err = -errno; break; } if (len == maxlen) { g_free(buf->data); maxlen *= 2; buf->data = g_malloc(maxlen); continue; } buf->size = len; buf->data[len] = 0; err = 0; break; } Matter of taste. [...] I skimmed a few more hunks, and they look good to me. Leaving full review to Aneesh.