From: Harlan Stenn Date: Sat, 4 Jul 2015 09:34:18 +0000 (+0000) Subject: [Bug 2866] segmentation fault at initgroups(). Harlan Stenn. X-Git-Tag: NTP_4_3_53~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f52d89c7290ead4815c33f80dd3b61bcc7dbc32;p=thirdparty%2Fntp.git [Bug 2866] segmentation fault at initgroups(). Harlan Stenn. bk: 5597a89aJBgXL6kFqCd4sxrVRvlExg --- 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);