From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=55626 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4Jeh-00079J-Rh for qemu-devel@nongnu.org; Mon, 28 Mar 2011 17:07:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4Jeg-0005jy-V2 for qemu-devel@nongnu.org; Mon, 28 Mar 2011 17:07:19 -0400 Received: from mail-ww0-f41.google.com ([74.125.82.41]:37910) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4Jeg-0005jm-N6 for qemu-devel@nongnu.org; Mon, 28 Mar 2011 17:07:18 -0400 Received: by wwi18 with SMTP id 18so2281008wwi.4 for ; Mon, 28 Mar 2011 14:07:17 -0700 (PDT) Date: Mon, 28 Mar 2011 22:06:42 +0100 From: Stefan Hajnoczi Message-ID: <20110328210642.GA11316@stefanha-thinkpad.localdomain> References: <1300418881-20972-1-git-send-email-mohan@in.ibm.com> <1300418881-20972-14-git-send-email-mohan@in.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1300418881-20972-14-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] Re: [V9 PATCH 13/13] virtio-9p: Chroot environment for other functions List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "M. Mohan Kumar" Cc: qemu-devel@nongnu.org On Fri, Mar 18, 2011 at 08:58:01AM +0530, M. Mohan Kumar wrote: > +static int get_dirfd(FsContext *fs_ctx, const char *path) > +{ > + int fd; > + char *dpath = qemu_strdup(path); > + char *last_component; > + > + /* path can not contain ".." */ > + last_component = strrchr(path, '/'); > + if (last_component && !strcmp(last_component, "/..")) { > + error_report("9p path request contains \"..\": %s\n", path); > + qemu_free(dpath); > + errno = EFAULT; > + return -1; > + } > + fd = passthrough_request(fs_ctx, NULL, dirname(dpath), 0, NULL, T_OPEN); > + if (fd < 0) { > + qemu_free(dpath); > + errno = -fd; > + fd = -1; > + } > + return fd; > +} dpath is leaked in the success case. I suggest writing the function like this: static int get_dirfd(FsContext *fs_ctx, const char *path) { int fd; char *dpath; char *last_component; /* path can not contain ".." */ last_component = strrchr(path, '/'); if (last_component && !strcmp(last_component, "/..")) { error_report("9p path request contains \"..\": %s\n", path); errno = EFAULT; return -1; } dpath = qemu_strdup(path); fd = passthrough_request(fs_ctx, NULL, dirname(dpath), 0, NULL, T_OPEN); qemu_free(dpath); if (fd < 0) { errno = -fd; fd = -1; } return fd; } > -static int local_utimensat(FsContext *s, const char *path, > - const struct timespec *buf) > +static int local_utimensat(FsContext *fs_ctx, const char *path, > + const struct timespec *buf) > { > - return qemu_utimensat(AT_FDCWD, rpath(s, path), buf, AT_SYMLINK_NOFOLLOW); > + if (fs_ctx->fs_sm == SM_PASSTHROUGH) { > + int fd, retval; > + fd = passthrough_request(fs_ctx, NULL, path, > + O_RDONLY | O_NONBLOCK | O_NOFOLLOW, NULL, T_OPEN); > + if (fd < 0) { > + errno = -fd; > + return -1; > + } > + retval = futimens(fd, buf); > + close(fd); > + return retval; errno is clobbered here. Stefan