From f2e59a4ee0f4df4ce765a342c9415ceddd58b01c Mon Sep 17 00:00:00 2001 From: Dang Huynh Date: Sat, 16 Nov 2024 16:12:48 +0000 Subject: [PATCH] fbd-ledctrl: Add null pointer check for groups The set_perms function does not check if getgrnam returns a null pointer. This causes the fbd-ledctrl to crash when a non-existent group is passed. --- src/fbd-ledctrl.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fbd-ledctrl.c b/src/fbd-ledctrl.c index d49b14d..f20a0f6 100644 --- a/src/fbd-ledctrl.c +++ b/src/fbd-ledctrl.c @@ -124,6 +124,10 @@ set_perms (const char *sysfs_path, const char *trigger, const char *gname) gboolean success = TRUE; group = getgrnam (gname); + if (!group) { + fprintf (stderr, "Failed to get group %s\n", gname); + return FALSE; + } if (!set_sysfs_attr_perm (sysfs_path, LED_BRIGHTNESS_ATTR, group->gr_gid)) return FALSE;