[PATCH] weston-launch: fix incorrect group read in weston_launch_allowed

comic fans comicfans44 at gmail.com
Fri Mar 18 03:45:24 UTC 2016


>From 6f46060d55c206ba2b98634bff64e9b78b93f125 Mon Sep 17 00:00:00 2001
From: comic fans <comicfans44 at gmail.com>
Date: Fri, 18 Mar 2016 17:56:46 +0800
Subject: [PATCH] weston-launch: fix incorrect group read in
 weston_launch_allowed

read_groups return array of n gid_t, not NULL terminated .
---
 src/weston-launch.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/weston-launch.c b/src/weston-launch.c
index b8dfb17..686f6bf 100644
--- a/src/weston-launch.c
+++ b/src/weston-launch.c
@@ -113,23 +113,22 @@ struct weston_launch {
 union cmsg_data { unsigned char b[4]; int fd; };

 static gid_t *
-read_groups(void)
+read_groups(int * n)
 {
-    int n;
     gid_t *groups;

-    n = getgroups(0, NULL);
+    *n = getgroups(0, NULL);

-    if (n < 0) {
+    if (*n < 0) {
         fprintf(stderr, "Unable to retrieve groups: %m\n");
         return NULL;
     }

-    groups = malloc(n * sizeof(gid_t));
+    groups = malloc(*n * sizeof(gid_t));
     if (!groups)
         return NULL;

-    if (getgroups(n, groups) < 0) {
+    if (getgroups(*n, groups) < 0) {
         fprintf(stderr, "Unable to retrieve groups: %m\n");
         free(groups);
         return NULL;
@@ -143,6 +142,7 @@ weston_launch_allowed(struct weston_launch *wl)
     struct group *gr;
     gid_t *groups;
     int i;
+    int n;
 #ifdef HAVE_SYSTEMD_LOGIN
     char *session, *seat;
     int err;
@@ -153,9 +153,9 @@ weston_launch_allowed(struct weston_launch *wl)

     gr = getgrnam("weston-launch");
     if (gr) {
-        groups = read_groups();
+        groups = read_groups(&n);
         if (groups) {
-            for (i = 0; groups[i]; ++i) {
+            for (i = 0; i<n; ++i) {
                 if (groups[i] == gr->gr_gid) {
                     free(groups);
                     return true;
-- 
2.7.3


More information about the wayland-devel mailing list