Index: app/xdm/session.c =================================================================== RCS file: /cvs/xorg/app/xdm/session.c,v retrieving revision 1.7 diff -u -r1.7 session.c --- app/xdm/session.c 3 Jun 2006 00:05:24 -0000 1.7 +++ app/xdm/session.c 5 Jun 2006 11:05:30 -0000 @@ -492,8 +492,14 @@ else ResetServer (d); if (removeAuth) { - setgid (verify.gid); - setuid (verify.uid); + if (setgid (verify.gid) == -1) { + LogError( "SessionExit: setgid: %s\n", strerror(errno)); + exit(status); + } + if (setuid (verify.uid) == -1) { + LogError( "SessionExit: setuid: %s\n", strerror(errno)); + exit(status); + } RemoveUserAuthorization (d, &verify); #if defined(K5AUTH) && !defined(USE_PAM) /* PAM modules should handle this */ /* do like "kdestroy" program */ Index: app/xdm/xdmshell.c =================================================================== RCS file: /cvs/xorg/app/xdm/xdmshell.c,v retrieving revision 1.3 diff -u -r1.3 xdmshell.c --- app/xdm/xdmshell.c 14 Jul 2005 22:58:25 -0000 1.3 +++ app/xdm/xdmshell.c 5 Jun 2006 11:05:30 -0000 @@ -183,7 +183,11 @@ #endif /* make xdm run in a non-setuid environment */ - setuid (geteuid()); + if (setuid (geteuid()) == -1) { + fprintf(stderr, "%s: cannot setuid (error %d, %s)\r\n", + ProgramName, errno, strerror(errno)); + exit(1); + } /* * exec /usr/bin/X11/xdm -nodaemon -udpPort 0 Index: app/xf86dga/dga.c =================================================================== RCS file: /cvs/xorg/app/xf86dga/dga.c,v retrieving revision 1.2 diff -u -r1.2 dga.c --- app/xf86dga/dga.c 23 Apr 2004 19:54:47 -0000 1.2 +++ app/xf86dga/dga.c 5 Jun 2006 11:05:30 -0000 @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -141,7 +142,10 @@ #ifndef __UNIXOS2__ /* Give up root privs */ - setuid(getuid()); + if (setuid(getuid()) == -1) { + fprintf(stderr, "Unable to change uid: %s\n", strerror(errno)); + exit(2); + } #endif XF86DGASetViewPort(dis, DefaultScreen(dis), 0, 0); Index: app/xinit/xinit.c =================================================================== RCS file: /cvs/xorg/app/xinit/xinit.c,v retrieving revision 1.4 diff -u -r1.4 xinit.c --- app/xinit/xinit.c 4 Oct 2005 01:27:34 -0000 1.4 +++ app/xinit/xinit.c 5 Jun 2006 11:05:31 -0000 @@ -1,5 +1,5 @@ /* $Xorg: xinit.c,v 1.5 2001/02/09 02:05:49 xorgcvs Exp $ */ -/* $XdotOrg: app/xinit/xinit.c,v 1.4 2005-10-04 01:27:34 ajax Exp $ */ +/* $XdotOrg: $ */ /* @@ -692,7 +692,10 @@ startClient(char *client[]) { if ((clientpid = vfork()) == 0) { - setuid(getuid()); + if (setuid(getuid()) == -1) { + Error("cannot change uid: %s\n", strerror(errno)); + _exit(ERR_EXIT); + } setpgrp(0, getpid()); environ = newenviron; #ifdef __UNIXOS2__ Index: app/xload/xload.c =================================================================== RCS file: /cvs/xorg/app/xload/xload.c,v retrieving revision 1.2 diff -u -r1.2 xload.c --- app/xload/xload.c 23 Apr 2004 19:54:57 -0000 1.2 +++ app/xload/xload.c 5 Jun 2006 11:05:32 -0000 @@ -34,7 +34,7 @@ * xload - display system load average in a window */ - +#include #include #include #include @@ -162,8 +162,17 @@ /* For security reasons, we reset our uid/gid after doing the necessary system initialization and before calling any X routines. */ InitLoadPoint(); - setgid(getgid()); /* reset gid first while still (maybe) root */ - setuid(getuid()); + /* reset gid first while still (maybe) root */ + if (setgid(getgid()) == -1) { + fprintf(stderr, "%s: setgid failed: %s\n", + ProgramName, strerror(errno)); + exit(1); + } + if (setuid(getuid()) == -1) { + fprintf(stderr, "%s: setuid failed: %s\n", + ProgramName, strerror(errno)); + exit(1); + } XtSetLanguageProc(NULL, (XtLanguageProc) NULL, NULL); Index: lib/xtrans/Xtranslcl.c =================================================================== RCS file: /cvs/xorg/lib/xtrans/Xtranslcl.c,v retrieving revision 1.4 diff -u -r1.4 Xtranslcl.c --- lib/xtrans/Xtranslcl.c 8 Nov 2005 06:33:26 -0000 1.4 +++ lib/xtrans/Xtranslcl.c 5 Jun 2006 11:06:03 -0000 @@ -360,7 +360,10 @@ uid_t saved_euid; saved_euid = geteuid(); - setuid( getuid() ); /** sets the euid to the actual/real uid **/ + /** sets the euid to the actual/real uid **/ + if (setuid( getuid() ) == -1) { + exit(1); + } if( chown( slave, saved_euid, -1 ) < 0 ) { exit( 1 ); } @@ -369,7 +372,13 @@ } waitpid(saved_pid, &exitval, 0); - + if (WIFEXITED(exitval) && WEXITSTATUS(exitval) != 0) { + close(fd); + close(server); + PRMSG(1, "PTSOpenClient: cannot set the owner of %s\n", + slave, 0, 0); + return(-1); + } if (chmod(slave, 0666) < 0) { close(fd); close(server); Index: xserver/xorg/hw/xfree86/common/xf86Init.c =================================================================== RCS file: /cvs/xorg/xserver/xorg/hw/xfree86/common/xf86Init.c,v retrieving revision 1.37 diff -u -r1.37 xf86Init.c --- xserver/xorg/hw/xfree86/common/xf86Init.c 1 Jun 2006 19:37:53 -0000 1.37 +++ xserver/xorg/hw/xfree86/common/xf86Init.c 5 Jun 2006 11:06:13 -0000 @@ -1896,7 +1897,11 @@ FatalError("xf86RunVtInit: fork failed (%s)\n", strerror(errno)); break; case 0: /* child */ - setuid(getuid()); + if (setuid(getuid()) == -1) { + xf86Msg(X_ERROR, "xf86RunVtInit: setuid failed (%s)\n", + strerror(errno)); + exit(255); + } /* set stdin, stdout to the consoleFd */ for (i = 0; i < 2; i++) { if (xf86Info.consoleFd != i) { Index: xserver/xorg/hw/xfree86/os-support/shared/libc_wrapper.c =================================================================== RCS file: /cvs/xorg/xserver/xorg/hw/xfree86/os-support/shared/libc_wrapper.c,v retrieving revision 1.11 diff -u -r1.11 libc_wrapper.c --- xserver/xorg/hw/xfree86/os-support/shared/libc_wrapper.c 25 Mar 2006 19:52:04 -0000 1.11 +++ xserver/xorg/hw/xfree86/os-support/shared/libc_wrapper.c 5 Jun 2006 11:06:14 -0000 @@ -1270,7 +1270,10 @@ #ifndef SELF_CONTAINED_WRAPPER xf86DisableIO(); #endif - setuid(getuid()); + if (setuid(getuid()) == -1) { + ErrorF("xf86Execl: setuid() failed: %s\n", strerror(errno)); + exit(255); + } #if !defined(SELF_CONTAINED_WRAPPER) /* set stdin, stdout to the consoleFD, and leave stderr alone */ for (i = 0; i < 2; i++) Index: xserver/xorg/hw/xfree86/parser/write.c =================================================================== RCS file: /cvs/xorg/xserver/xorg/hw/xfree86/parser/write.c,v retrieving revision 1.3 diff -u -r1.3 write.c --- xserver/xorg/hw/xfree86/parser/write.c 3 Jul 2005 07:01:37 -0000 1.3 +++ xserver/xorg/hw/xfree86/parser/write.c 5 Jun 2006 11:06:15 -0000 @@ -170,7 +170,10 @@ strerror(errno)); return 0; case 0: /* child */ - setuid(getuid()); + if (setuid(getuid() == -1) + FatalError("xf86writeConfigFile(): " + "setuid failed(%s)\n", + strerror(errno)); ret = doWriteConfigFile(filename, cptr); exit(ret); break; Index: xserver/xorg/os/utils.c =================================================================== RCS file: /cvs/xorg/xserver/xorg/os/utils.c,v retrieving revision 1.26 diff -u -r1.26 utils.c --- xserver/xorg/os/utils.c 1 Jun 2006 22:06:41 -0000 1.26 +++ xserver/xorg/os/utils.c 5 Jun 2006 11:06:17 -0000 @@ -1718,8 +1718,10 @@ case -1: /* error */ p = -1; case 0: /* child */ - setgid(getgid()); - setuid(getuid()); + if (setgid(getgid()) == -1) + _exit(127); + if (setuid(getuid()) == -1) + _exit(127); execl("/bin/sh", "sh", "-c", command, (char *)NULL); _exit(127); default: /* parent */ @@ -1770,8 +1772,10 @@ xfree(cur); return NULL; case 0: /* child */ - setgid(getgid()); - setuid(getuid()); + if (setgid(getgid()) == -1) + _exit(127); + if (setuid(getuid()) == -1) + _exit(127); if (*type == 'r') { if (pdes[1] != 1) { /* stdout */ @@ -1845,8 +1849,10 @@ xfree(cur); return NULL; case 0: /* child */ - setgid(getgid()); - setuid(getuid()); + if (setgid(getgid()) == -1) + _exit(127); + if (setuid(getuid()) == -1) + _exit(127); if (*type == 'r') { if (pdes[1] != 1) { /* stdout */