diff -Naur nagios-4.3.1/base/nagios.c nagios-4.3.1-CVE-2017-12847/base/nagios.c --- nagios-4.3.1/base/nagios.c 2017-02-23 21:00:40.000000000 +0100 +++ nagios-4.3.1-CVE-2017-12847/base/nagios.c 2017-11-19 15:28:45.898806034 +0100 @@ -592,6 +592,22 @@ program_start = time(NULL); my_free(mac->x[MACRO_PROCESSSTARTTIME]); asprintf(&mac->x[MACRO_PROCESSSTARTTIME], "%llu", (unsigned long long)program_start); + + /* enter daemon mode (unless we're restarting...) */ + if(daemon_mode == TRUE && sigrestart == FALSE) { + + result = daemon_init(); + + /* we had an error daemonizing, so bail... */ + if(result == ERROR) { + logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR, TRUE, "Bailing out due to failure to daemonize. (PID=%d)", (int)getpid()); + cleanup(); + exit(EXIT_FAILURE); + } + + /* get new PID */ + nagios_pid = (int)getpid(); + } /* drop privileges */ if(drop_privileges(nagios_user, nagios_group) == ERROR) { @@ -612,21 +628,6 @@ /* error has already been logged */ exit(EXIT_FAILURE); } - /* enter daemon mode (unless we're restarting...) */ - if(daemon_mode == TRUE && sigrestart == FALSE) { - - result = daemon_init(); - - /* we had an error daemonizing, so bail... */ - if(result == ERROR) { - logit(NSLOG_PROCESS_INFO | NSLOG_RUNTIME_ERROR, TRUE, "Bailing out due to failure to daemonize. (PID=%d)", (int)getpid()); - cleanup(); - exit(EXIT_FAILURE); - } - - /* get new PID */ - nagios_pid = (int)getpid(); - } /* this must be logged after we read config data, as user may have changed location of main log file */ logit(NSLOG_PROCESS_INFO, TRUE, "Nagios %s starting... (PID=%d)\n", PROGRAM_VERSION, (int)getpid());