From 13f48a05f784e3c8b0762420c5d4f5540f80a59d Mon Sep 17 00:00:00 2001 From: CaS Date: Tue, 2 Jul 2002 14:20:32 +0000 Subject: [PATCH] Security fix. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14004 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Tools/gdomap.c | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 385885c3d..389a1461b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-07-02 Richard Frith-Macdonald + + * Tools/gdomap.c: Don't write to pidfile until *after* setuid away + from root. Bug reported by James Kehl + 2002-07-01 Richard Frith-Macdonald * Source/Additions/GSMime.m: Correct test for multipart content when diff --git a/Tools/gdomap.c b/Tools/gdomap.c index ecc7550e2..ffada4f11 100644 --- a/Tools/gdomap.c +++ b/Tools/gdomap.c @@ -4466,7 +4466,7 @@ printf( } } - if (pidfile) { + if (pidfile) { FILE *fptr = fopen(pidfile, "at"); @@ -4479,7 +4479,6 @@ printf( fprintf(fptr, "%d\n", (int) getpid()); fclose(fptr); } - } /* * Ensure we don't have any open file descriptors which may refer @@ -4574,6 +4573,21 @@ printf( setuid (uid); } #endif /* __MINGW__ */ + + if (pidfile) + { + FILE *fptr = fopen(pidfile, "at"); + + if (fptr == 0) + { + sprintf(ebuf, "Unable to open pid file - '%s'", pidfile); + gdomap_log(LOG_CRIT); + exit(1); + } + fprintf(fptr, "%d\n", (int) getpid()); + fclose(fptr); + } + #if !defined(__svr4__) /* * As another level of paranoia - restrict this process to /tmp