@@ -299,15 +299,13 @@ exec_mailer(int pipein)
299299 syslog (LOG_ERR , _ ("unable to dup stdin: %m" )); // -V618
300300 sudo_debug_printf (SUDO_DEBUG_ERROR ,
301301 "unable to dup stdin: %s" , strerror (errno ));
302- sudo_debug_exit (__func__ , __FILE__ , __LINE__ , sudo_debug_subsys );
303- _exit (127 );
302+ goto bad ;
304303 }
305304
306305 /* Build up an argv based on the mailer path and flags */
307306 if ((mflags = strdup (evl_conf -> mailerflags )) == NULL ) {
308307 syslog (LOG_ERR , _ ("unable to allocate memory" )); // -V618
309- sudo_debug_exit (__func__ , __FILE__ , __LINE__ , sudo_debug_subsys );
310- _exit (127 );
308+ goto bad ;
311309 }
312310 argv [0 ] = sudo_basename (mpath );
313311
@@ -326,11 +324,23 @@ exec_mailer(int pipein)
326324 if (setuid (ROOT_UID ) != 0 ) {
327325 sudo_debug_printf (SUDO_DEBUG_ERROR , "unable to change uid to %u" ,
328326 ROOT_UID );
327+ goto bad ;
328+ }
329+ if (setgid (evl_conf -> mailgid ) != 0 ) {
330+ sudo_debug_printf (SUDO_DEBUG_ERROR , "unable to change gid to %u" ,
331+ (unsigned int )evl_conf -> mailgid );
332+ goto bad ;
333+ }
334+ if (setgroups (1 , & evl_conf -> mailgid ) != 0 ) {
335+ sudo_debug_printf (SUDO_DEBUG_ERROR , "unable to set groups to %u" ,
336+ (unsigned int )evl_conf -> mailgid );
337+ goto bad ;
329338 }
330339 if (evl_conf -> mailuid != ROOT_UID ) {
331340 if (setuid (evl_conf -> mailuid ) != 0 ) {
332341 sudo_debug_printf (SUDO_DEBUG_ERROR , "unable to change uid to %u" ,
333342 (unsigned int )evl_conf -> mailuid );
343+ goto bad ;
334344 }
335345 }
336346 sudo_debug_exit (__func__ , __FILE__ , __LINE__ , sudo_debug_subsys );
@@ -342,6 +352,9 @@ exec_mailer(int pipein)
342352 sudo_debug_printf (SUDO_DEBUG_ERROR , "unable to execute %s: %s" ,
343353 mpath , strerror (errno ));
344354 _exit (127 );
355+ bad :
356+ sudo_debug_exit (__func__ , __FILE__ , __LINE__ , sudo_debug_subsys );
357+ _exit (127 );
345358}
346359
347360/* Send a message to the mailto user */
0 commit comments