diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2013-09-18 22:14:09 -0700 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2013-09-18 22:14:09 -0700 |
commit | 6a7c8492cc5160ab392a82ba6c106b1fada9136d (patch) | |
tree | 8b247ee74cfdb45884823f07bb75ef595de7c738 | |
parent | 81b49639495f22f1d8f8a6978029db3d0b07fe0b (diff) | |
download | weston-6a7c8492cc5160ab392a82ba6c106b1fada9136d.tar.gz weston-6a7c8492cc5160ab392a82ba6c106b1fada9136d.tar.bz2 weston-6a7c8492cc5160ab392a82ba6c106b1fada9136d.zip |
weston-launch: Use fstat to make sure we stat the right fd
Instead of the racy stat+open, open first and then use fstat. We want to
make sure we're stating the fd we'll be sending to weston and nothing else.
-rw-r--r-- | src/weston-launch.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/weston-launch.c b/src/weston-launch.c index 059010c4..05f15c1d 100644 --- a/src/weston-launch.c +++ b/src/weston-launch.c @@ -280,9 +280,6 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len) /* Ensure path is null-terminated */ ((char *) message)[len-1] = '\0'; - if (stat(message->path, &s) < 0) - goto err0; - fd = open(message->path, message->flags); if (fd < 0) { fprintf(stderr, "Error opening device %s: %m\n", @@ -290,6 +287,13 @@ handle_open(struct weston_launch *wl, struct msghdr *msg, ssize_t len) goto err0; } + if (fstat(fd, &s) < 0) { + close(fd); + fd = -1; + fprintf(stderr, "Failed to stat %s\n", message->path); + goto err0; + } + if (major(s.st_rdev) != INPUT_MAJOR && major(s.st_rdev) != DRM_MAJOR) { close(fd); |