Safer handling of argument-logging memory of cwd
[exim.git] / src / src / exim.c
index ad7635d98fe7fce0ae5bc0928a550cb3c374d7b2..810550dd509657acb04b5afef14837569ad09f87 100644 (file)
@@ -187,7 +187,15 @@ DEBUG(D_process_info) debug_printf("set_process_info: %s", process_info);
 va_end(ap);
 }
 
+/***********************************************
+*            Handler for SIGTERM               *
+***********************************************/
 
+static void
+term_handler(int sig)
+{
+  exit(1);
+}
 
 
 /*************************************************
@@ -1624,6 +1632,8 @@ testing harness; do a fast initial check, and then the whole thing. */
 
 running_in_test_harness =
   *running_status == '<' && Ustrcmp(running_status, "<<<testing>>>") == 0;
+if (running_in_test_harness)
+  debug_store = TRUE;
 
 /* The C standard says that the equivalent of setlocale(LC_ALL, "C") is obeyed
 at the start of a program; however, it seems that some environments do not
@@ -1676,6 +1686,10 @@ descriptive text. */
 set_process_info("initializing");
 os_restarting_signal(SIGUSR1, usr1_handler);
 
+/* If running in a dockerized environment, the TERM signal is only
+delegated to the PID 1 if we request it by setting an signal handler */
+if (getpid() == 1) signal(SIGTERM, term_handler);
+
 /* SIGHUP is used to get the daemon to reconfigure. It gets set as appropriate
 in the daemon code. For the rest of Exim's uses, we ignore it. */
 
@@ -4077,8 +4091,11 @@ if (((debug_selector & D_any) != 0 || LOGGING(arguments))
   Ustrcpy(p, "cwd= (failed)");
 
   Ustrncpy(p + 4, initial_cwd, big_buffer_size-5);
+  p += 4 + Ustrlen(initial_cwd);
+  /* in case p is near the end and we don't provide enough space for
+   * string_format to be willing to write. */
+  *p = '\0';
 
-  while (*p) p++;
   (void)string_format(p, big_buffer_size - (p - big_buffer), " %d args:", argc);
   while (*p) p++;
   for (i = 0; i < argc; i++)
@@ -5138,6 +5155,8 @@ if (recipients_arg >= argc && !extract_recipients && !smtp_input)
   {
   if (version_printed)
     {
+    if (Ustrchr(config_main_filelist, ':'))
+      printf("Configuration file search path is %s\n", config_main_filelist);
     printf("Configuration file is %s\n", config_main_filename);
     return EXIT_SUCCESS;
     }