[PATCH] weston-launch: fix incorrect group read in weston_launch_allowed
Pekka Paalanen
ppaalanen at gmail.com
Tue May 3 12:59:43 UTC 2016
Hi comic,
git-am tells me:
Applying: weston-launch: fix incorrect group read in weston_launch_allowed
Using index info to reconstruct a base tree...
error: patch failed: src/weston-launch.c:113
error: src/weston-launch.c: patch does not apply
error: Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Patch failed at 0001 weston-launch: fix incorrect group read in weston_launch_allowed
On Fri, 18 Mar 2016 11:45:24 +0800
comic fans <comicfans44 at gmail.com> wrote:
> 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 .
Yes, this fix looks correct.
The existing code is not comparing to NULL though, but to (gid_t)0. 0
is usually a valid group, too.
> ---
> 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)
Don't add space after unary asterisk.
> {
> - 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) {
Use spaces around binary operators.
> if (groups[i] == gr->gr_gid) {
> free(groups);
> return true;
Thanks,
pq
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 811 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160503/a22696f1/attachment-0001.sig>
More information about the wayland-devel
mailing list