From 2be8a3fe06d41fe1fb33fe527699a8fd3b4e1149 Mon Sep 17 00:00:00 2001 From: Harlan Stenn Date: Sat, 4 Jul 2015 09:34:18 +0000 Subject: [PATCH] [Bug 2866] segmentation fault at initgroups(). Harlan Stenn. bk: 5597a89aJBgXL6kFqCd4sxrVRvlExg --- ChangeLog | 1 + ntpd/ntpd.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 150d438d1..dd2f71e39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ --- * [Bug 2864] 4.2.8p3 fails to compile on Windows. Juergen Perlinger +* [Bug 2866] segmentation fault at initgroups(). Harlan Stenn. * [Bug 2867] ntpd with autokey active crashed by 'ntpq -crv'. J.Perlinger * libntp/emalloc.c: Remove explicit include of stdint.h. Harlan Stenn. * Put Unity CPPFLAGS items in unity_config.h. Harlan Stenn. diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index 529e6ce1b..766285665 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -937,10 +937,17 @@ getgroup: msyslog(LOG_ERR, "Cannot setegid() to group `%s': %m", group); exit (-1); } - if (group) - setgroups(1, &sw_gid); - else - initgroups(pw->pw_name, pw->pw_gid); + if (group) { + if (0 != setgroups(1, &sw_gid)) { + msyslog(LOG_ERR, "setgroups(1, %d) failed: %m", sw_gid); + exit (-1); + } + } + else if (pw) + if (0 != initgroups(pw->pw_name, pw->pw_gid)) { + msyslog(LOG_ERR, "initgroups(<%s>, %d) filed: %m", pw->pw_name, pw->pw_gid); + exit (-1); + } if (user && setuid(sw_uid)) { msyslog(LOG_ERR, "Cannot setuid() to user `%s': %m", user); exit (-1); -- 2.47.3