[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() help
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() helper |
Date: |
Mon, 27 Feb 2017 12:44:30 +0000 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
On Sun, Feb 26, 2017 at 11:42:03PM +0100, Greg Kurz wrote:
> +int openat_nofollow(int dirfd, const char *path, int flags, mode_t mode)
> +{
> + int fd;
> +
> + fd = dup(dirfd);
> + if (fd == -1) {
> + return -1;
> + }
> +
> + while (*path) {
> + const char *c;
> + int next_fd;
> + char *head;
> +
> + head = g_strdup(path);
> + c = strchr(path, '/');
> + if (c) {
> + head[c - path] = 0;
> + next_fd = openat_dir(fd, head);
> + } else {
> + next_fd = openat_file(fd, head, flags, mode);
> + }
> + g_free(head);
> + if (next_fd == -1) {
> + close_preserve_errno(fd);
> + return -1;
> + }
> + close(fd);
> + fd = next_fd;
> +
> + if (!c) {
> + break;
> + }
> + path = c + 1;
> + }
> +
> + return fd;
> +}
If I understand the Linux openat(2) implementation correctly this
function fails with ENOENT if:
1. An absolute path is given
2. A path contains consecutive slashes ("a///b")
Both of these behaviors are problematic. If the function doesn't
support absolute paths it should be called relative_openat_nofollow()
and have an error if path[0] == '/'.
I believe guests can pass in paths with consecutive slashes, so the
function must cope with them.
signature.asc
Description: PGP signature
- [Qemu-devel] [PATCH v2 00/28] Series short description, Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 01/28] 9pfs: local: move xattr security ops to 9p-xattr.c, Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 02/28] 9pfs: remove side-effects in local_init(), Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 03/28] 9pfs: remove side-effects in local_open() and local_opendir(), Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() helper, Greg Kurz, 2017/02/26
- Re: [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() helper,
Stefan Hajnoczi <=
- Re: [Qemu-devel] [PATCH v2 04/28] 9pfs: introduce openat_nofollow() helper, Eric Blake, 2017/02/27
- [Qemu-devel] [PATCH v2 05/28] 9pfs: local: keep a file descriptor on the shared folder, Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 06/28] 9pfs: local: open/opendir: don't follow symlinks, Greg Kurz, 2017/02/26
- [Qemu-devel] [PATCH v2 07/28] 9pfs: local: lgetxattr: don't follow symlinks, Greg Kurz, 2017/02/26