From fe4d29888306e62f3bbf964b3fdb8126ddbe8f6e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 16 Nov 2017 01:52:55 +0100 Subject: [PATCH] Fix CVE-2017-11747: Create PID file before dropping privileges. Resolves #106 Signed-off-by: Michael Adam --- src/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.c b/src/main.c index ae2a3a8..1bda6c7 100644 --- a/src/main.c +++ b/src/main.c @@ -436,6 +436,15 @@ main (int argc, char **argv) exit (EX_OSERR); } + /* Create pid file before we drop privileges */ + if (config.pidpath) { + if (pidfile_create (config.pidpath) < 0) { + fprintf (stderr, "%s: Could not create PID file.\n", + argv[0]); + exit (EX_OSERR); + } + } + /* Switch to a different user if we're running as root */ if (geteuid () == 0) change_user (argv[0]); @@ -448,15 +457,6 @@ main (int argc, char **argv) exit (EX_SOFTWARE); } - /* Create pid file after we drop privileges */ - if (config.pidpath) { - if (pidfile_create (config.pidpath) < 0) { - fprintf (stderr, "%s: Could not create PID file.\n", - argv[0]); - exit (EX_OSERR); - } - } - if (child_pool_create () < 0) { fprintf (stderr, "%s: Could not create the pool of children.\n",