Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 20)
+++ trunk/src/sh_unix.c	(revision 22)
@@ -307,6 +307,6 @@
     *p = '0' + (u % 10);
     u /= 10;
-  } while (u);
-  if (iisneg == 1) {
+  } while (u && (p != str));
+  if ((iisneg == 1) && (p != str)) {
     --p;
     *p = '-';
@@ -323,5 +323,5 @@
 extern int OnlyStderr; 
 
-int safe_logger (int signal, int method, pid_t thepid)
+int safe_logger (int signal, int method, char * details)
 {
   int i = 0;
@@ -331,17 +331,19 @@
   char  str[128];
   char  * p;
-
+  
   char l0[64], l1[64], l2[64], l3[64];
   char a0[32], a1[32], a2[32];
   char e0[128];
   char msg[128];
-
+  
   char * locations[] = { NULL, NULL, NULL, NULL, NULL };
   char * envp[]      = { NULL, NULL };
   char * argp[]      = { NULL, NULL, NULL, NULL, NULL };
-
+  
+  pid_t  thepid = getpid();
+  
   if ((sh.flag.isdaemon == S_FALSE) || (OnlyStderr == S_TRUE))
     method = 1;
-
+  
   /* seems that solaris cc needs this way of initializing ...
    */
@@ -350,23 +352,11 @@
   locations[2] = l2;
   locations[3] = l3;
-
+  
   envp[0] = e0;
-
+  
   argp[0] = a0;
   argp[1] = a1;
   argp[2] = a2;
-
-  strcpy (l0, _("/usr/bin/logger"));                   /* known to fit  */
-  strcpy (l1, _("/usr/sbin/logger"));                  /* known to fit  */
-  strcpy (l2, _("/usr/ucb/logger"));                   /* known to fit  */
-  strcpy (l3, _("/bin/logger"));                       /* known to fit  */
-
-  strcpy (a0, _("logger"));                            /* known to fit  */
-  strcpy (a1, _("-p"));                                /* known to fit  */
-  strcpy (a2, _("daemon.alert"));                      /* known to fit  */
-
-  strcpy (e0,                                          /* known to fit  */
-	  _("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin"));
-
+  
   sl_strlcpy(msg, _("samhain["), 128);
   p = safe_itoa((int) thepid, str, 128);
@@ -375,5 +365,10 @@
   if (signal == 0)
     {
-      sl_strlcat(msg, _("]: out of memory"), 128);
+      if (details == NULL) {
+	sl_strlcat(msg, _("]: out of memory"), 128);
+      } else {
+	sl_strlcat(msg, _("]: "), 128);
+	sl_strlcat(msg, details, 128);
+      }
     }
   else 
@@ -393,4 +388,18 @@
     return 0;
   }
+
+  sl_strlcpy (l0, _("/usr/bin/logger"), 64);
+  sl_strlcpy (l1, _("/usr/sbin/logger"), 64);
+  sl_strlcpy (l2, _("/usr/ucb/logger"), 64);
+  sl_strlcpy (l3, _("/bin/logger"), 64);
+
+  sl_strlcpy (a0, _("logger"), 32);
+  sl_strlcpy (a1, _("-p"), 32);
+  sl_strlcpy (a2, _("daemon.alert"), 32);
+
+  sl_strlcpy (e0,
+	      _("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin"),
+	      128);
+
   while (locations[i] != NULL) {
     status = stat(locations[i], &buf);
@@ -414,4 +423,22 @@
 }
 
+int safe_fatal (int signal, int method, char * details, 
+		char * file, int line)
+{
+  char msg[128];
+  char str[128];
+  char * p;
+  p = safe_itoa((int) line, str, 128);
+  sl_strlcpy(msg, _("FATAL: "), 128);
+  sl_strlcat(msg, file, 128);
+  sl_strlcat(msg, ": ", 128);
+  if (p && (*p)) {
+    sl_strlcat(msg, p   , 128);
+    sl_strlcat(msg, ": ", 128);
+  }
+  sl_strlcat(msg, details, 128);
+  safe_logger (signal, method, msg);
+  _exit(EXIT_FAILURE);
+}
 
 extern char sh_sig_msg[64];
@@ -451,5 +478,5 @@
 	{
 	  chdir ("/");
-	  safe_logger (mysignal, 0, getpid());
+	  safe_logger (mysignal, 0, NULL);
 	}
       _exit(mysignal);
@@ -504,5 +531,5 @@
     memset (skey, '\0', sizeof(sh_key_t));
   if (immediate_exit_fast < 2)
-    safe_logger (mysignal, 0, getpid());
+    safe_logger (mysignal, 0, NULL);
   _exit(mysignal);
 #else
@@ -518,5 +545,5 @@
       close_ipc ();
 #endif
-      safe_logger (mysignal, 0, getpid());
+      safe_logger (mysignal, 0, NULL);
       chdir ("/");
       raise(SIGFPE);
@@ -819,5 +846,5 @@
 /* checksum the own binary
  */
-int sh_unix_self_hash (char * c)
+int sh_unix_self_hash (const char * c)
 {
   char message[512];
@@ -891,5 +918,5 @@
 
 /* added    Tue Feb 22 10:36:44 NFT 2000 Rainer Wichmann            */
-static int tf_add_trusted_user_int(char * c)
+static int tf_add_trusted_user_int(const char * c)
 {
   register struct passwd *          w;
@@ -919,5 +946,5 @@
 }
 
-int tf_add_trusted_user(char * c)
+int tf_add_trusted_user(const char * c)
 {
   int    i;
@@ -1229,4 +1256,5 @@
   char ** env1;
   int   envlen = 0;
+  size_t len;
 
   SL_ENTER(_("sh_unix_copyenv"));
@@ -1248,6 +1276,7 @@
   envlen = 0;
 
-  while (env0 != NULL && env0[envlen] != NULL) { 
-    env1[envlen] = malloc (strlen(env0[envlen]) + 1); /* only once */
+  while (env0 != NULL && env0[envlen] != NULL) {
+    len = strlen(env0[envlen]) + 1;
+    env1[envlen] = malloc (len); /* only once */
     if (env1[envlen] == NULL)
       {
@@ -1255,5 +1284,5 @@
 	SL_RET0(_("sh_unix_copyenv"));
       }
-    strcpy(env1[envlen], env0[envlen]);                /* known to fit  */
+    sl_strlcpy(env1[envlen], env0[envlen], len);
     ++envlen;
   }
@@ -1435,5 +1464,5 @@
 
   (void) uname (&buf);
-
+  /* flawfinder: ignore */ /* ff bug, ff sees system() */
   sl_strlcpy (sh.host.system,  buf.sysname, SH_MINIBUF);
   sl_strlcpy (sh.host.release, buf.release, SH_MINIBUF);
@@ -1639,4 +1668,5 @@
 	  aud_exit(FIL__, __LINE__, EXIT_FAILURE);
 	}
+      /* flawfinder: ignore */
       return (chroot(chroot_dir));
     }
@@ -1923,5 +1953,5 @@
 }
 
-int sh_unix_settimeserver (char * address)
+int sh_unix_settimeserver (const char * address)
 {
 
@@ -2096,5 +2126,5 @@
 /* whether to use localtime for file timesatams in logs
  */
-int sh_unix_uselocaltime (char * c)
+int sh_unix_uselocaltime (const char * c)
 {
   int i;
@@ -2732,5 +2762,5 @@
 }
 
-int sh_unix_set_io_limit (char * c)
+int sh_unix_set_io_limit (const char * c)
 {
   long val;
@@ -2772,7 +2802,8 @@
   if (tmpFile.size < fbuf->st_size)
     {
-      strcpy(fileHash,                         /* known to fit */
-	     sh_tiger_generic_hash (filename, TIGER_FD, tmpFile.size, 
-				    alert_timeout));
+      sl_strlcpy(fileHash,
+		sh_tiger_generic_hash (filename, TIGER_FD, tmpFile.size, 
+				       alert_timeout),
+		KEY_LEN+1);
 
       /* return */
@@ -2781,6 +2812,7 @@
 
  out:
-  strcpy(fileHash,                              /* known to fit */
-	 _("000000000000000000000000000000000000000000000000"));
+  sl_strlcpy(fileHash,
+	     _("000000000000000000000000000000000000000000000000"),
+	     KEY_LEN+1);
   SL_RETURN( -1, _("sh_unix_checksum_size"));
 }
@@ -2903,6 +2935,7 @@
     {
       if (fileHash != NULL)
-	strcpy(fileHash,                              /* known to fit */
-	       _("000000000000000000000000000000000000000000000000"));
+	sl_strlcpy(fileHash,
+		   _("000000000000000000000000000000000000000000000000"),
+		   KEY_LEN+1);
     }
   
@@ -2920,6 +2953,7 @@
 	  if ((theFile->check_mask & MODI_CHK) == 0)
 	    {
-	      strcpy(fileHash,                         /* known to fit */
-		     _("000000000000000000000000000000000000000000000000"));
+	      sl_strlcpy(fileHash,
+			 _("000000000000000000000000000000000000000000000000"),
+			 KEY_LEN+1);
 	    }
 	  else if ((theFile->check_mask & MODI_PREL) != 0 && 
@@ -2929,13 +2963,16 @@
 	      if (0 != sh_prelink_run (theFile->fullpath, 
 				       fileHash, alert_timeout))
-		strcpy(fileHash,                       /* known to fit */
-		       _("000000000000000000000000000000000000000000000000"));
+		sl_strlcpy(fileHash,
+			   _("000000000000000000000000000000000000000000000000"),
+			   KEY_LEN+1);
 	    }
 	  else
 	    {
 	      tiger_fd = rval_open;
-	      strcpy(fileHash,                         /* known to fit */
-		     sh_tiger_generic_hash (theFile->fullpath, TIGER_FD, 0, 
-					    alert_timeout));
+	      sl_strlcpy(fileHash,
+			 sh_tiger_generic_hash (theFile->fullpath, 
+						TIGER_FD, 0, 
+						alert_timeout),
+			 KEY_LEN+1);
 	      if ((theFile->check_mask & MODI_SGROW) != 0)
 		{
@@ -2960,6 +2997,7 @@
 	  if ((theFile->check_mask & MODI_CHK) == 0)
 	    {
-	      strcpy(fileHash,                         /* known to fit */
-		     _("000000000000000000000000000000000000000000000000"));
+	      sl_strlcpy(fileHash,
+			 _("000000000000000000000000000000000000000000000000"),
+			 KEY_LEN+1);
 	    }
 	  else if (policy == SH_LEVEL_PRELINK &&
@@ -2969,6 +3007,7 @@
 	      if (0 != sh_prelink_run (theFile->fullpath, 
 				       fileHash, alert_timeout))
-		strcpy(fileHash,                       /* known to fit */
-		       _("000000000000000000000000000000000000000000000000"));
+		sl_strlcpy(fileHash,
+			   _("000000000000000000000000000000000000000000000000"),
+			   KEY_LEN+1);
 	    }
 	  else
@@ -3145,4 +3184,5 @@
       linknamebuf = SH_ALLOC(PATH_MAX);
 
+      /* flawfinder: ignore */
       linksize    = readlink (theFile->fullpath, linknamebuf, PATH_MAX-1);
 
@@ -3160,4 +3200,6 @@
 	  SH_FREE(tmp2);
 	  SH_FREE(linknamebuf);
+	  theFile->linkpath[0] = '-';
+	  theFile->linkpath[1] = '\0';
 	  SL_RETURN((-1),_("sh_unix_getinfo"));
 	}
