Changeset 22 for trunk/src


Ignore:
Timestamp:
Feb 23, 2006, 12:03:58 AM (19 years ago)
Author:
rainer
Message:

Minor code revisions.

Location:
trunk/src
Files:
36 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_utils.c

    r21 r22  
    1010
    1111  int ret = 0;
     12#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
    1213  char input[16] = "foobar";
    13 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
    1414
    1515  ret = sh_util_obscure_ok ("0xA1,0xA2,0xA3");
  • trunk/src/samhain.c

    r20 r22  
    382382   */
    383383  (void) sl_strlcpy (sh.host.name,  _("localhost"),  SH_MINIBUF);
    384   sh.host.system[0]     = '\0';
     384  sh.host.system[0]     = '\0'; /* flawfinder: ignore *//* ff bug */
    385385  sh.host.release[0]    = '\0';
    386386  sh.host.machine[0]    = '\0';
     
    582582  skey->mailkey_old[0]  = '\0';
    583583  skey->mailkey_new[0]  = '\0';
    584   skey->crypt[0]        = '\0';
     584  skey->crypt[0]        = '\0'; /* flawfinder: ignore *//* ff bug */
    585585  skey->session[0]      = '\0';
    586586  skey->vernam[0]       = '\0';
     
    725725  char         exef[128];
    726726
     727  if (!pidlist)
     728    return NULL;
     729
    727730  for (i = 0; i < 65535; ++i) pidlist[i] = 0;
    728731  i = 0;
    729732
    730733  if (0 != stat(SH_INSTALL_PATH, &buf))
    731     return NULL;
     734    {
     735      free(pidlist);
     736      return NULL;
     737    }
    732738
    733739  ino = (long) buf.st_ino;
    734740   
    735741  if (NULL == (dp = opendir("/proc")))
    736     return NULL;
     742    {
     743      free(pidlist);
     744      return NULL;
     745    }
    737746  while (NULL != (d = readdir(dp)) && i < 65535)
    738747    {
     
    860869
    861870
    862   fullpath = malloc(strlen(SH_INSTALL_PATH)+1);
     871  fullpath = strdup (SH_INSTALL_PATH);
    863872  if (fullpath == NULL)
    864     { perror(_("malloc")); exit (1); }
    865   else
    866     strcpy(fullpath, SH_INSTALL_PATH);                 /* known to fit  */
    867 
    868   argp[0] = malloc(strlen(SH_INSTALL_PATH)+1);
     873    { perror(_("strdup")); exit (1); }
     874
     875  argp[0]  = strdup (SH_INSTALL_PATH);
    869876  if (argp[0] == NULL)
    870     { perror(_("malloc")); exit (1); }
    871   else
    872     strcpy(argp[0], SH_INSTALL_PATH);                  /* known to fit  */
    873 
     877    { perror(_("strdup")); exit (1); }
    874878
    875879  for (times = 1; times < 32; ++times)  argp[times] = NULL;
     
    879883  for (times = 2; times < res; ++times) 
    880884    {
    881       argp[times-1] = malloc(strlen(argv[times])+1);
     885      argp[times-1] = strdup (argv[times]);
    882886      if (argp[times-1] == NULL)
    883         { perror(_("malloc")); exit (1); }
    884       else
    885         strcpy(argp[times-1], argv[times]);              /* known to fit  */
     887        { perror(_("strdup")); exit (1); }
    886888    }
    887889
     
    903905            _exit(4);
    904906          }
    905         (void) execv(fullpath, argp);
     907        (void) execv(fullpath, argp); /* flawfinder: ignore *//* wtf? */
    906908        if (errno == EPERM)
    907909          _exit(4);
     
    941943      pidlist = procdirSamhain ();
    942944      if (pid == 0 && NULL == pidlist) /* pid file not found */
    943         return (0);
     945        {
     946          free(fullpath);
     947          return (0);
     948        }
    944949         
    945950      status = 0;
     
    956961            }
    957962        }
     963      free(fullpath);
    958964      if (status == 7)
    959965        return 0;
     
    992998        }
    993999    }
    994 
     1000  free(fullpath); /* silence smatch false positive */
    9951001  exit (1); /* no exit handler installed yet */
    9961002  /*@notreached@*/
     
    10221028/* Add a new schedule to the linked list of schedules
    10231029 */
    1024 static sh_schedule_t * sh_set_schedule_int (char * str,
     1030static sh_schedule_t * sh_set_schedule_int (const char * str,
    10251031                                            sh_schedule_t * FileSchedIn,
    10261032                                            /*@out@*/ int * status)
     
    10521058/* Add a new schedule to the linked list FileSchedOne
    10531059 */
    1054 int sh_set_schedule_one (char * str)
     1060int sh_set_schedule_one (const char * str)
    10551061{
    10561062  int status;
     
    10611067/* Add a new schedule to the linked list FileSchedTwo
    10621068 */
    1063 int sh_set_schedule_two (char * str)
     1069int sh_set_schedule_two (const char * str)
    10641070{
    10651071  int status;
     
    12141220  /* Save the timezone.
    12151221   */
    1216   if ((tzptr = getenv("TZ")) != NULL)
     1222  if (NULL != (tzptr = getenv("TZ"))) /* flawfinder: ignore */
    12171223    {
    12181224      tzlen       = strlen(tzptr);
    1219        sh.timezone = malloc (tzlen + 1);
    1220       if (sh.timezone != NULL)
    1221          (void) sl_strlcpy (sh.timezone, tzptr, tzlen + 1);
     1225      if (tzlen < 1024)
     1226        {
     1227          sh.timezone = malloc (tzlen + 1);
     1228          if (sh.timezone != NULL)
     1229            (void) sl_strlcpy (sh.timezone, tzptr, tzlen + 1);
     1230        }
     1231      else
     1232        sh.timezone = NULL;
    12221233    }
    12231234  else
  • trunk/src/samhain_setpwd.c

    r1 r22  
    11#include "config_xor.h"
    2 
    3 #ifdef HAVE_BROKEN_INCLUDES
    4 #define _ANSI_C_SOURCE
    5 #define _POSIX_SOURCE
    6 #endif
    72
    83#include <stdio.h>
     
    138#include <unistd.h>
    149#include <sys/types.h>
     10#include <sys/wait.h>
    1511#include <sys/stat.h>
    1612#include <fcntl.h>
     13#include <errno.h>
     14#include <sys/time.h>
    1715#include <time.h>
    1816
     17#if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_YIELD)
     18#include <sched.h>
     19#endif
     20
     21#if defined(HAVE_INT_32)
     22typedef unsigned int UINT32;
     23#elif defined(HAVE_LONG_32)
     24typedef unsigned long UINT32;
     25#elif defined(HAVE_SHORT_32)
     26typedef unsigned short UINT32;
     27#endif
     28
     29#define TAUS_MAX 4294967295UL
     30
     31static UINT32 taus_state[3];
     32
     33static UINT32 taus_get ()
     34{
     35
     36#define TAUSWORTHE(s,a,b,c,d) ((s &c) <<d) ^ (((s <<a) ^s) >>b)
     37  taus_state[0] = TAUSWORTHE (taus_state[0], 13, 19, 4294967294UL, 12);
     38  taus_state[1] = TAUSWORTHE (taus_state[1],  2, 25, 4294967288UL,  4);
     39  taus_state[2] = TAUSWORTHE (taus_state[2],  3, 11, 4294967280UL, 17);
     40  return (taus_state[0] ^ taus_state[1] ^ taus_state[2]);
     41}
     42
     43static void taus_seed ()
     44{
     45  unsigned char buf[12];
     46  unsigned char buf2[12];
     47  unsigned char buf3[12];
     48  ssize_t count;
     49  size_t nbytes = sizeof(buf);
     50  size_t where  = 0;
     51
     52  struct timeval t1, t2;
     53  UINT32 delta, k[3];
     54  int i, j;
     55
     56  int fd = open ("/dev/urandom", O_RDONLY);
     57
     58  if (fd == -1)
     59    {
     60      gettimeofday(&t1, NULL);
     61      delta = t1.tv_usec;
     62      memcpy(&buf[0], &delta, 4);
     63      gettimeofday(&t1, NULL);
     64      delta = t1.tv_usec;
     65      memcpy(&buf[4], &delta, 4);
     66      gettimeofday(&t1, NULL);
     67      delta = t1.tv_usec;
     68      memcpy(&buf[8], &delta, 4);
     69      goto second;
     70    }
     71
     72  while (nbytes) {
     73    count = read(fd, &buf[where], nbytes);
     74    if (count == -1 && errno == EINTR)
     75      continue;
     76    where  += count;
     77    nbytes -= count;
     78  } while (count == -1 && errno == EINTR);
     79
     80  close(fd);
     81
     82 second:
     83  for (i = 0; i < 12; ++i)
     84    {
     85      gettimeofday(&t1, NULL);
     86      if (0 == fork())
     87        _exit(EXIT_SUCCESS);
     88      wait(NULL);
     89      gettimeofday(&t2, NULL);
     90      delta = t2.tv_usec - t1.tv_usec;
     91      buf2[i] = (unsigned char) delta;
     92    }
     93
     94  for (i = 0; i < 12; ++i)
     95    {
     96      gettimeofday(&t1, NULL);
     97      for (j = 0; j < 32768; ++j)
     98        {
     99          if (0 == kill (j,0))
     100            k[i % 3] ^= j;
     101        }
     102      gettimeofday(&t2, NULL);
     103      delta = t2.tv_usec - t1.tv_usec;
     104      buf3[i] ^= (unsigned char) delta;
     105    }
     106
     107  memcpy(&taus_state[0], &buf3[0], 4);
     108  memcpy(&taus_state[1], &buf3[4], 4);
     109  memcpy(&taus_state[2], &buf3[8], 4);
     110
     111  taus_state[0] ^= k[0];
     112  taus_state[1] ^= k[1];
     113  taus_state[2] ^= k[2];
     114 
     115  memcpy(&k[0], &buf2[0], 4);
     116  memcpy(&k[1], &buf2[4], 4);
     117  memcpy(&k[2], &buf2[8], 4);
     118
     119  taus_state[0] ^= k[0];
     120  taus_state[1] ^= k[1];
     121  taus_state[2] ^= k[2];
     122 
     123  memcpy(&k[0], &buf[0], 4);
     124  memcpy(&k[1], &buf[4], 4);
     125  memcpy(&k[2], &buf[8], 4);
     126
     127  taus_state[0] ^= k[0];
     128  taus_state[1] ^= k[1];
     129  taus_state[2] ^= k[2];
     130
     131  taus_state[0] |= (UINT32) 0x03;
     132  taus_state[1] |= (UINT32) 0x09;
     133  taus_state[2] |= (UINT32) 0x17;
     134}
    19135
    20136#ifdef SH_STEALTH
     
    112228
    113229  char * newn;
     230  size_t nlen;
    114231  int    oldf;
    115232  int    newf;
     
    196313  (void) umask (0);
    197314
    198   srand(time(NULL) ^ getpid());
     315  taus_seed();
    199316
    200317  bytecount = 0;
     
    206323  oldf = open(argv[1], O_RDONLY);
    207324
    208   newn = (char *) malloc (strlen(argv[1])+strlen(argv[2])+2);
    209   strcpy(newn, argv[1]);
    210   strcat(newn, ".");
    211   strcat(newn, argv[2]);
     325  nlen = strlen(argv[1])+strlen(argv[2])+2;
     326  newn = (char *) malloc (nlen);
     327  strncpy(newn, argv[1], nlen); newn[nlen-1] = '\0';
     328  strncat(newn, ".", nlen);     newn[nlen-1] = '\0';
     329  strncat(newn, argv[2], nlen); newn[nlen-1] = '\0';
    212330  newf = open(newn, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
    213331
     
    265383                      (unsigned char) *found_it);
    266384
    267               ccd = (unsigned char) (256.0 * rand()/(RAND_MAX+1.0));
     385              ccd = (unsigned char) (256.0 * (taus_get()/(TAUS_MAX+1.0)));
    268386              sprintf(&newpwd[i*2], _("%02x"),
    269387                      (unsigned char) ccd);
     
    340458                      (unsigned char) *found_it);
    341459
    342               ccd = (unsigned char) (256.0 * rand()/(RAND_MAX+1.0));
     460              ccd = (unsigned char) (256.0 * taus_get()/(TAUS_MAX+1.0));
    343461              sprintf(&newpwd[i*2], _("%02x"),
    344462                      (unsigned char) ccd);
  • trunk/src/sh_calls.c

    r20 r22  
    8282/* Set aud functions
    8383 */
    84 int sh_aud_set_functions(char * str_s)
     84int sh_aud_set_functions(const char * str_s)
    8585{
    8686  int i = 0;
  • trunk/src/sh_database.c

    r18 r22  
    4040#include "sh_error.h"
    4141#include "sh_utils.h"
    42 
    43 extern int safe_logger (int signal, int method, pid_t thepid);
    4442
    4543#undef  FIL__
     
    253251static int  sh_persistent_dbconn = S_TRUE;
    254252
    255 int sh_database_use_persistent (char * str)
     253int sh_database_use_persistent (const char * str)
    256254{
    257255  return sh_util_flagval (str, &sh_persistent_dbconn);
    258256}
    259257
    260 static int insert_value (char * ptr, char * str)
     258static int insert_value (char * ptr, const char * str)
    261259{
    262260  if (!ptr || !str)
     
    276274 
    277275
    278 int sh_database_set_database (char * str)
     276int sh_database_set_database (const char * str)
    279277{
    280278  return insert_value (db_name, str);
    281279}
    282 int sh_database_set_table (char * str)
     280int sh_database_set_table (const char * str)
    283281{
    284282  return insert_value (db_table, str);
    285283}
    286 int sh_database_set_host (char * str)
     284int sh_database_set_host (const char * str)
    287285{
    288286  return insert_value (db_host, str);
    289287}
    290 int sh_database_set_user (char * str)
     288int sh_database_set_user (const char * str)
    291289{
    292290  return insert_value (db_user, str);
    293291}
    294 int sh_database_set_password (char * str)
     292int sh_database_set_password (const char * str)
    295293{
    296294  return insert_value (db_password, str);
     
    568566 oracle_doconnect:
    569567
    570   if (!getenv("ORACLE_HOME"))
     568  if (!getenv("ORACLE_HOME")) /* flawfinder: ignore */
    571569    {
    572570      sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
     
    14821480}
    14831481
    1484 int sh_database_add_to_hash  (char * str)
     1482int sh_database_add_to_hash  (const char * str)
    14851483{
    14861484  int i;
     
    16921690static int enter_wrapper = 1;
    16931691
    1694 int set_enter_wrapper (char * str)
     1692int set_enter_wrapper (const char * str)
    16951693{
    16961694  return sh_util_flagval(str, &enter_wrapper);
  • trunk/src/sh_entropy.c

    r1 r22  
    170170        memset( &addr, 0, sizeof(addr) );
    171171        addr.sun_family = AF_UNIX;
    172         strcpy( addr.sun_path, name );              /* known to fit  */
     172        sl_strlcpy( addr.sun_path, name, sizeof(addr.sun_path) );
    173173        addr_len = offsetof( struct sockaddr_un, sun_path )
    174174                   + strlen( addr.sun_path );
     
    570570  char * arg[4];
    571571  char * envp[2];
     572  size_t len;
    572573
    573574  SL_ENTER(_("sh_popen"));
     
    580581  if (sh.timezone != NULL)
    581582    {
    582       envp[0] = malloc (sl_strlen(sh.timezone) + 4);     /* free() ok     */
     583      len = sl_strlen(sh.timezone) + 4;
     584      envp[0] = malloc (len);     /* free() ok     */
    583585      if (envp[0] != NULL)
    584         sprintf (envp[0], "TZ=%s", sh.timezone);         /* known to fit  */
     586        sl_snprintf (envp[0], len, "TZ=%s", sh.timezone);
    585587      else
    586588        envp[0] = NULL;
     
    778780        sl_strlcat(combuf, _(source[i].command), 80);
    779781
     782        /* flawfinder: ignore */
    780783        if ( access (combuf, X_OK) == 0)
    781784          {
  • trunk/src/sh_err_console.c

    r1 r22  
    112112/* Enable the message queue
    113113 */
    114 int enable_msgq(char * foo)
     114int enable_msgq(const char * foo)
    115115{
    116116  int i;
     
    234234/* ---- Set the console device. ----
    235235 */
    236 int sh_log_set_console (char * address)
     236int sh_log_set_console (const char * address)
    237237{
    238238  SL_ENTER(_("sh_log_set_console"));
  • trunk/src/sh_err_log.c

    r20 r22  
    604604  char            sigkey_old[KEY_LEN+1];
    605605  char            sigkey_new[KEY_LEN+1];
    606   char            crypt[KEY_LEN+1];
     606  char            crypto[KEY_LEN+1];
    607607  struct  lfstc * next;
    608608} open_logfile;
     
    613613
    614614#ifdef SH_WITH_SERVER
    615 int set_flag_sep_log (char * str)
     615int set_flag_sep_log (const char * str)
    616616{
    617617  return sh_util_flagval(str, &flag_sep_log);
     
    642642  char               * sigkey_new;
    643643  char               * sigkey_old;
    644   char               * crypt;
     644  char               * crypto;
    645645
    646646  SL_ENTER(_("sh_log_file"));
     
    734734      memset(current->sigkey_old, (int)'\0', KEY_LEN+1);
    735735      memset(current->sigkey_new, (int)'\0', KEY_LEN+1);
    736       memset(current->crypt,      (int)'\0', KEY_LEN+1);
     736      memset(current->crypto,     (int)'\0', KEY_LEN+1);
    737737      current->next            = logfile_list;
    738738      logfile_list             = current;
     
    841841      sigkey_old = current->sigkey_old;
    842842      sigkey_new = current->sigkey_new;
    843       crypt      = current->crypt;
     843      crypto     = current->crypto;
    844844    }
    845845  else
     
    847847      sigkey_old = skey->sigkey_old;
    848848      sigkey_new = skey->sigkey_new;
    849       crypt      = skey->crypt;
     849      crypto     = skey->crypt;      /* flawfinder: ignore */
    850850    }
    851851
     
    869869      /* Copy it to 'crypt' for encryption.
    870870       */
    871       (void) sl_strlcpy(crypt, sigkey_new, KEY_LEN+1);
     871      (void) sl_strlcpy(crypto, sigkey_new, KEY_LEN+1);
    872872
    873873      /* Use message and compiled-in key to encrypt.
    874874       */
    875875      BREAKEXIT(sh_util_encode);
    876       sh_util_encode(crypt, log_msg.msg, 0, 'B');
     876      sh_util_encode(crypto, log_msg.msg, 0, 'B');
    877877
    878878      /* Send out the key.
     
    900900
    901901      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_KEY_MAIL,
    902                        sh.prg_name, crypt,
    903                        crypt, log_msg.timestamp);
     902                       sh.prg_name, crypto,
     903                       crypto, log_msg.timestamp);
    904904
    905905      /* send to other allowed channels
     
    913913
    914914      sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_START_KEY,
    915                        sh.prg_name, crypt);
     915                       sh.prg_name, crypto);
    916916
    917917      /* Cleanup.
     
    926926
    927927
    928       memset (crypt, (int) '\0', KEY_LEN);
     928      memset (crypto, (int) '\0', KEY_LEN);
    929929      sh.flag.log_start    = S_FALSE; 
    930930      current->log_start   = S_FALSE;
     
    949949  (void) sl_strlcpy (sigkey_old, sigkey_new, KEY_LEN+1);
    950950
    951   /*@-bufferoverflowhigh -usedef@*/
     951  /*@-usedef@*/
    952952#ifdef SH_USE_XML
    953953  if (log_msg.timestamp[0] != '\0')
    954     sprintf(log_msg.sig,                            /* known to fit  */
     954    sl_snprintf(log_msg.sig, sizeof(log_msg.sig),
    955955#ifdef FIX_XML
    956             _("\n<sig>%s%s</sig></log>\n"),          /* <sig> FIX XML */
    957 #else
    958             _("\nsig>%s%s</sig></log>\n"),          /* <sig> FIX XML */
    959 #endif
    960             log_msg.signature, log_msg.timestamp);
     956                _("\n<sig>%s%s</sig></log>\n"),          /* <sig> FIX XML */
     957#else
     958                _("\nsig>%s%s</sig></log>\n"),          /* <sig> FIX XML */
     959#endif
     960                log_msg.signature, log_msg.timestamp);
    961961  else
    962     sprintf(log_msg.sig,                            /* known to fit  */
     962    sl_snprintf(log_msg.sig, sizeof(log_msg.sig),
    963963#ifdef FIX_XML
    964             _("\n<sig>%s</sig></log>\n"),            /* <sig> FIX XML */
    965 #else
    966             _("\nsig>%s</sig></log>\n"),            /* <sig> FIX XML */
    967 #endif
    968             log_msg.signature);
    969   /*@+bufferoverflowhigh +usedef@*/
     964                _("\n<sig>%s</sig></log>\n"),            /* <sig> FIX XML */
     965#else
     966                _("\nsig>%s</sig></log>\n"),            /* <sig> FIX XML */
     967#endif
     968                log_msg.signature);
     969  /*@+usedef@*/
    970970
    971971#ifdef SH_STEALTH
  • trunk/src/sh_err_syslog.c

    r1 r22  
    110110/* set syslog facility
    111111 */
    112 int  sh_log_set_facility (char * c)
     112int  sh_log_set_facility (const char * c)
    113113{
    114114  int loop = 0;
  • trunk/src/sh_error.c

    r20 r22  
    102102/* convert a string to a numeric priority
    103103 */
    104 int sh_error_convert_level (char * str_s);
     104int sh_error_convert_level (const char * str_s);
    105105
    106106static int  IsInitialized = BAD;
     
    219219}
    220220
    221 static int sh_error_set_classmask (/*@notnull@*/char * c, int * facility_mask)
     221static int sh_error_set_classmask (const char * str, int * facility_mask)
    222222{
    223223  char * p;
     
    225225  unsigned int    i;
    226226  size_t len;
     227  char * c;
    227228
    228229  SL_ENTER(_("sh_error_set_classmask"));
    229230 
    230   if (c == NULL)
     231  if (str == NULL)
    231232    SL_RETURN( -1, _("sh_error_set_classmask"));
    232233
     
    234235    (void) sh_error_init();
    235236
    236   if (c[0] == (char) 34)
    237     ++c;
    238   len = strlen(c);
     237  if (str[0] == (char) 34)
     238    ++str;
     239  len = strlen(str);
     240
     241  c = SH_ALLOC(len+1);
     242  sl_strlcpy(c, str, len+1);
     243
    239244  if (c[len-1] == (char) 34)
    240245    c[len-1] = '\0';
     
    273278  } while (p);
    274279
     280  SH_FREE(c);
    275281  SL_RETURN( 0, _("sh_error_set_classmask"));
    276282}
    277283
    278 int sh_error_log_mask (char * c)
     284int sh_error_log_mask (const char * c)
    279285{
    280286  return (sh_error_set_classmask(c, &(errFlags.log_class)));
    281287}
    282 int sh_error_mail_mask (char * c)
     288int sh_error_mail_mask (const char * c)
    283289{
    284290  return (sh_error_set_classmask(c, &(errFlags.mail_class)));
    285291}
    286 int sh_error_print_mask (char * c)
     292int sh_error_print_mask (const char * c)
    287293{
    288294  return (sh_error_set_classmask(c, &(errFlags.print_class)));
    289295}
    290 int sh_error_export_mask (char * c)
     296int sh_error_export_mask (const char * c)
    291297{
    292298  return (sh_error_set_classmask(c, &(errFlags.export_class)));
    293299}
    294 int sh_error_syslog_mask (char * c)
     300int sh_error_syslog_mask (const char * c)
    295301{
    296302  return (sh_error_set_classmask(c, &(errFlags.syslog_class)));
    297303}
    298 int sh_error_external_mask (char * c)
     304int sh_error_external_mask (const char * c)
    299305{
    300306  return (sh_error_set_classmask(c, &(errFlags.external_class)));
    301307}
    302 int sh_error_database_mask (char * c)
     308int sh_error_database_mask (const char * c)
    303309{
    304310  return (sh_error_set_classmask(c, &(errFlags.database_class)));
    305311}
    306 int sh_error_prelude_mask (char * c)
     312int sh_error_prelude_mask (const char * c)
    307313{
    308314  return (sh_error_set_classmask(c, &(errFlags.prelude_class)));
     
    446452};
    447453
    448 int sh_error_convert_level (char * str_s)
     454int sh_error_convert_level (const char * str_s)
    449455{
    450456  int i;
     
    472478/* --- Set severity levels. ---
    473479 */
    474 int sh_error_set_iv (int iv, char *  str_s)
     480int sh_error_set_iv (int iv, const char *  str_s)
    475481{
    476482  int level = (-1);
     
    11261132            {
    11271133              int retval;
     1134              size_t ex_len;
    11281135
    11291136              /* will truncate to 65280 bytes
    11301137               */
    11311138              export_block = 1;
    1132               ex_msg = SH_ALLOC (64 + sl_strlen(lmsg->msg) + 1);
    1133               /*@-bufferoverflowhigh@*/
    1134               sprintf(ex_msg, _("%d?%u?%s"),             /* known to fit  */
    1135                            severity, class, lmsg->msg);
    1136               /*@-bufferoverflowhigh@*/
     1139              ex_len = 64 + sl_strlen(lmsg->msg) + 1;
     1140              ex_msg = SH_ALLOC (ex_len);
     1141
     1142              sl_snprintf(ex_msg, ex_len, _("%d?%u?%s"),
     1143                      severity, class, lmsg->msg);
     1144
    11371145              retval = sh_forward (ex_msg);
    11381146              SH_FREE(ex_msg);
     
    13061314/* allocate space for user-defined message header
    13071315 */
    1308 int sh_error_ehead (/*@null@*/char * str_s)
     1316int sh_error_ehead (/*@null@*/const char * str_s)
    13091317{
    13101318  size_t size;
    1311   char * s;
     1319  const char * s;
    13121320
    13131321  SL_ENTER(_("sh_error_ehead"));
     
    13241332 
    13251333  size = /*@i@*/strlen(s);
    1326   if (/*@i@*/s[size-1] == (char) 34) --size;
     1334  if (/*@i@*/s[size-1] == (char) 34) --size; /* truncate */
    13271335
    13281336  if (ehead_format != NULL)
     
    14821490      len      = sl_strlen(lmsg->msg);
    14831491      /*@i@*/required = sl_vsnprintf(&(lmsg->msg[len]),
    1484                               (lmsg->msg_len - len), lmsg->format, vl);
     1492                                     (lmsg->msg_len - len), lmsg->format, vl);
    14851493      if ( (required + len) > (lmsg->msg_len - 4) )
    14861494        {
  • trunk/src/sh_extern.c

    r1 r22  
    364364             
    365365              PDBGC(5);
    366               sprintf(pname, _("/proc/self/fd/%d"),      /* known to fit  */
    367                            pfd);
    368               if (access(pname, R_OK|X_OK) == 0)
     366              sl_snprintf(pname, sizeof(pname), _("/proc/self/fd/%d"), pfd);
     367              if (access(pname, R_OK|X_OK) == 0) /* flawfinder: ignore */
    369368                {
    370369                  PDBGC(6);
     
    402401           * --  execute path if executable
    403402           */
    404           if (0 == access(task->command, R_OK|X_OK))
     403          if (0 == access(task->command, R_OK|X_OK)) /* flawfinder: ignore */
    405404            {
    406405              PDBGC(5);
     
    544543              task->exit_status = WEXITSTATUS(task->exit_status);
    545544              if ((flag_err_debug == SL_TRUE) || (task->exit_status != 0))
    546                 sprintf(infomsg,                         /* known to fit  */
    547                         _("Subprocess exited normally with status %d"),
    548                         task->exit_status);
     545                sl_snprintf(infomsg, sizeof(infomsg),
     546                            _("Subprocess exited normally with status %d"),
     547                            task->exit_status);
    549548            }
    550549          else if (WIFSIGNALED(task->exit_status) != 0)
    551550            {
    552               sprintf(infomsg,                           /* known to fit  */
    553                       _("Subprocess terminated by signal %d"),
    554                       WTERMSIG(task->exit_status));
     551              sl_snprintf(infomsg, sizeof(infomsg),
     552                          _("Subprocess terminated by signal %d"),
     553                          WTERMSIG(task->exit_status));
    555554              task->exit_status = EXIT_FAILURE;
    556555            }
    557556          else if (WIFSTOPPED(task->exit_status) != 0)
    558557            {
    559               sprintf(infomsg,                           /* known to fit  */
    560                       _("Subprocess stopped by signal %d, killing"),
    561                       WSTOPSIG(task->exit_status));
     558              sl_snprintf(infomsg, sizeof(infomsg),
     559                          _("Subprocess stopped by signal %d, killing"),
     560                          WSTOPSIG(task->exit_status));
    562561              task->exit_status = EXIT_FAILURE;
    563562              (void) aud_kill (FIL__, __LINE__, task->pid, 9);
     
    567566          else
    568567            {
    569               sprintf(infomsg,                           /* known to fit  */
    570                       _("Subprocess exit status unknown"));
     568              sl_snprintf(infomsg, sizeof(infomsg),
     569                          _("Subprocess exit status unknown"));
    571570              task->exit_status = EXIT_FAILURE;
    572571            }
     
    581580            }
    582581          (void) aud_kill (FIL__, __LINE__, task->pid, 9);
    583           sprintf(infomsg,                               /* known to fit  */
    584                   _("Subprocess not yet exited, killing"));
     582          sl_snprintf(infomsg, sizeof(infomsg),
     583                      _("Subprocess not yet exited, killing"));
    585584          task->exit_status = EXIT_FAILURE;
    586585          (void) waitpid (task->pid, NULL, 0);
     
    588587      else
    589588        {
    590           sprintf(infomsg,                               /* known to fit  */
    591                   _("Waitpid returned error %d\n"), errno);
     589          sl_snprintf(infomsg, sizeof(infomsg),
     590                      _("Waitpid returned error %d\n"), errno);
    592591          task->exit_status = EXIT_FAILURE;
    593592        }
     
    646645
    647646
    648 int sh_ext_tas_add_envv(sh_tas_t * tas, char * key, char * val)
     647int sh_ext_tas_add_envv(sh_tas_t * tas, const char * key, const char * val)
    649648{
    650649  size_t sk = 0, sv = 0;
     
    697696}
    698697
    699 int sh_ext_tas_add_argv(sh_tas_t * tas, char * val)
     698int sh_ext_tas_add_argv(sh_tas_t * tas, const char * val)
    700699{
    701700  size_t sv = 0;
     
    722721}
    723722
    724 void sh_ext_tas_command(sh_tas_t * tas, char * command)
     723void sh_ext_tas_command(sh_tas_t * tas, const char * command)
    725724{
    726725  size_t len = sl_strlen(command);
     
    842841
    843842static
    844 int sh_ext_add_envv(char * key, char * val)
     843int sh_ext_add_envv(const char * key, const char * val)
    845844{
    846845  SL_ENTER(_("sh_ext_add_envv"));
     
    861860
    862861static
    863 int sh_ext_init(char * command)
     862int sh_ext_init(const char * command)
    864863{
    865864  sh_com_t * retval;
     
    896895
    897896static
    898 int sh_ext_uid (char * user, /*@out@*/uid_t * uid, /*@out@*/gid_t * gid)
     897int sh_ext_uid (const char * user, /*@out@*/uid_t * uid, /*@out@*/gid_t * gid)
    899898{
    900899  struct passwd * tempres;
     
    922921
    923922static
    924 int sh_ext_add (char * argstring, int * ntok, char * stok[])
     923int sh_ext_add (const char * argstring, int * ntok, char * stok[])
    925924{
    926925  int    i = 0;
    927926  size_t s;
    928927  char * p;
     928  char * new;
     929  size_t len;
    929930
    930931  SL_ENTER(_("sh_ext_add"));
     
    935936    }
    936937
     938  len = strlen(argstring) + 1;
     939  new = SH_ALLOC(len);
     940  sl_strlcpy(new, argstring, len);
     941
    937942  do
    938943    {
    939944      if (i == 0)
    940         p = strtok (argstring, ", \t");
     945        p = strtok (new, ", \t");
    941946      else
    942947        p = strtok (NULL, ", \t");
     
    957962
    958963  *ntok = i;
     964  SH_FREE(new);
    959965
    960966  SL_RETURN (0, _("sh_ext_add"));
     
    971977 * -- start a new external command, and add it to the list
    972978 */
    973 int sh_ext_setcommand(char * cmd)
     979int sh_ext_setcommand(const char * cmd)
    974980{
    975981  int i;
     
    10181024 * -- add keywords to the OR filter
    10191025 */
    1020 int sh_ext_add_or (char * str)
     1026int sh_ext_add_or (const char * str)
    10211027{
    10221028  if (ext_coms == NULL || ext_failed == (-1))
     
    10281034 * -- add keywords to the AND filter
    10291035 */
    1030 int sh_ext_add_and (char * str)
     1036int sh_ext_add_and (const char * str)
    10311037{
    10321038  if (ext_coms == NULL || ext_failed == (-1))
     
    10381044 * -- add keywords to the NOT filter
    10391045 */
    1040 int sh_ext_add_not (char * str)
     1046int sh_ext_add_not (const char * str)
    10411047{
    10421048  if (ext_coms == NULL || ext_failed == (-1))
     
    10481054 * -- add keywords to the CL argument list
    10491055 */
    1050 int sh_ext_add_argv (char * str)
     1056int sh_ext_add_argv (const char * str)
    10511057{
    10521058  if (ext_coms == NULL || ext_failed == (-1))
     
    10581064 * -- add a path to the environment
    10591065 */
    1060 int sh_ext_add_default (char * dummy)
    1061 {
    1062   /* while this assignment looks ridiculous, it is here to avoid
    1063    * an 'unused parameter' warning
    1064    */
    1065   char * p = (dummy == NULL ? dummy : NULL);
     1066int sh_ext_add_default (const char * dummy)
     1067{
     1068  (void) dummy;
     1069  char * p = NULL;
    10661070  int    i;
    10671071
     
    10841088 * -- add an environment variable
    10851089 */
    1086 int sh_ext_add_environ (char * str)
     1090int sh_ext_add_environ (const char * str)
    10871091{
    10881092  int i;
     
    10951099 * -- set deadtime
    10961100 */
    1097 int sh_ext_deadtime (char * str)
     1101int sh_ext_deadtime (const char * str)
    10981102{
    10991103  long    deadtime = 0;
     
    11191123 * -- define type
    11201124 */
    1121 int sh_ext_type (char * str)
     1125int sh_ext_type (const char * str)
    11221126{
    11231127  SL_ENTER(_("sh_ext_type"));
     
    11541158 * -- define checksum
    11551159 */
    1156 int sh_ext_checksum (char * str)
     1160int sh_ext_checksum (const char * str)
    11571161{
    11581162  SL_ENTER(_("sh_ext_checksum"));
     
    11751179 * -- choose privileges
    11761180 */
    1177 int sh_ext_priv (char * c)
     1181int sh_ext_priv (const char * c)
    11781182{
    11791183
  • trunk/src/sh_fifo.c

    r1 r22  
    8787    }
    8888
    89   strcpy (item->data, indat);                   /* known to fit  */
     89  sl_strlcpy (item->data, indat, len+1);
    9090  item->data[len] = '\0';
    9191
     
    143143    }
    144144
    145   strcpy (item->data, indat);                          /* known to fit  */
     145  sl_strlcpy (item->data, indat, len+1);
    146146  item->data[len] = '\0';
    147147
     
    195195  len         = sl_strlen(getit->data);
    196196  retval      = SH_ALLOC(len+1);
    197   strcpy (retval, getit->data);                        /* known to fit  */
    198   retval[len] = '\0';
     197  sl_strlcpy (retval, getit->data, len+1);
    199198 
    200199  memset(getit->data, 0, len);
  • trunk/src/sh_files.c

    r20 r22  
    7272#define FIL__  _("sh_files.c")
    7373
    74 extern int safe_logger (int signal, int method, pid_t thepid);
    75 
    7674extern int flag_err_debug;
    7775extern int flag_err_info;
    7876
    79 int sh_files_reportonce(char * c)
     77int sh_files_reportonce(const char * c)
    8078{
    8179  int i;
     
    8684}
    8785   
    88 int sh_files_fulldetail(char * c)
     86int sh_files_fulldetail(const char * c)
    8987{
    9088  int i;
     
    156154static int        sh_files_fullpath  (char * testdir, char * d_name,
    157155                                      char * statpath);
    158 static int        sh_files_pushdir   (int class, char * str_s);
    159 static int        sh_files_pushfile  (int class, char * str_s);
     156static int        sh_files_pushdir   (int class, const char * str_s);
     157static int        sh_files_pushfile  (int class, const char * str_s);
    160158static int        sh_files_checkdir  (int class, int rdepth, char * dirName,
    161159                                      char * relativeName);
     
    446444
    447445
    448 int sh_files_pushfile_prelink (char * str_s)
     446int sh_files_pushfile_prelink (const char * str_s)
    449447{
    450448  return (sh_files_pushfile (SH_LEVEL_PRELINK, str_s));
    451449}
    452450
    453 int sh_files_pushfile_user0 (char * str_s)
     451int sh_files_pushfile_user0 (const char * str_s)
    454452{
    455453  return (sh_files_pushfile (SH_LEVEL_USER0, str_s));
     
    457455
    458456
    459 int sh_files_pushfile_user1 (char * str_s)
     457int sh_files_pushfile_user1 (const char * str_s)
    460458{
    461459  return (sh_files_pushfile (SH_LEVEL_USER1, str_s));
     
    463461
    464462
    465 int sh_files_pushfile_ro (char * str_s)
     463int sh_files_pushfile_ro (const char * str_s)
    466464{
    467465  return (sh_files_pushfile (SH_LEVEL_READONLY, str_s));
    468466}
    469467
    470 int sh_files_pushfile_attr (char * str_s)
     468int sh_files_pushfile_attr (const char * str_s)
    471469{
    472470  return (sh_files_pushfile (SH_LEVEL_ATTRIBUTES, str_s));
    473471}
    474472
    475 int sh_files_pushfile_log (char * str_s)
     473int sh_files_pushfile_log (const char * str_s)
    476474{
    477475  return (sh_files_pushfile (SH_LEVEL_LOGFILES, str_s));
    478476}
    479477
    480 int sh_files_pushfile_glog (char * str_s)
     478int sh_files_pushfile_glog (const char * str_s)
    481479{
    482480  return (sh_files_pushfile (SH_LEVEL_LOGGROW, str_s));
    483481}
    484482
    485 int sh_files_pushfile_noig (char * str_s)
     483int sh_files_pushfile_noig (const char * str_s)
    486484{
    487485  return (sh_files_pushfile (SH_LEVEL_NOIGNORE, str_s));
    488486}
    489487
    490 int sh_files_pushfile_allig (char * str_s)
     488int sh_files_pushfile_allig (const char * str_s)
    491489{
    492490  return (sh_files_pushfile (SH_LEVEL_ALLIGNORE, str_s));
     
    511509/* set mask(class)
    512510 */
    513 static int sh_files_parse_mask (unsigned long * mask, char * str)
     511static int sh_files_parse_mask (unsigned long * mask, const char * str)
    514512{
    515513  int l, i = 0, act = 0, k = 0;
     
    602600}
    603601
    604 int sh_files_redef_prelink(char * str)
     602int sh_files_redef_prelink(const char * str)
    605603{
    606604  return (sh_files_parse_mask(&mask_PRELINK, str));
    607605}
    608 int sh_files_redef_user0(char * str)
     606int sh_files_redef_user0(const char * str)
    609607{
    610608  return (sh_files_parse_mask(&mask_USER0, str));
    611609}
    612 int sh_files_redef_user1(char * str)
     610int sh_files_redef_user1(const char * str)
    613611{
    614612  return (sh_files_parse_mask(&mask_USER1, str));
    615613}
    616 int sh_files_redef_readonly(char * str)
     614int sh_files_redef_readonly(const char * str)
    617615{
    618616  return (sh_files_parse_mask(&mask_READONLY, str));
    619617}
    620 int sh_files_redef_loggrow(char * str)
     618int sh_files_redef_loggrow(const char * str)
    621619{
    622620  return (sh_files_parse_mask(&mask_LOGGROW, str));
    623621}
    624 int sh_files_redef_logfiles(char * str)
     622int sh_files_redef_logfiles(const char * str)
    625623{
    626624  return (sh_files_parse_mask(&mask_LOGFILES, str));
    627625}
    628 int sh_files_redef_attributes(char * str)
     626int sh_files_redef_attributes(const char * str)
    629627{
    630628  return (sh_files_parse_mask(&mask_ATTRIBUTES, str));
    631629}
    632 int sh_files_redef_noignore(char * str)
     630int sh_files_redef_noignore(const char * str)
    633631{
    634632  return (sh_files_parse_mask(&mask_NOIGNORE, str));
    635633}
    636 int sh_files_redef_allignore(char * str)
     634int sh_files_redef_allignore(const char * str)
    637635{
    638636  return (sh_files_parse_mask(&mask_ALLIGNORE, str));
     
    725723      if (zfileList == NULL)
    726724        {
    727           (void) safe_logger (0, 0, getpid());
     725          (void) safe_logger (0, 0, NULL);
    728726          aud__exit(FIL__, __LINE__, EXIT_FAILURE);
    729727        }
     
    734732  if (-1 == ret)
    735733    {
    736       (void) safe_logger (0, 0, getpid());
     734      (void) safe_logger (0, 0, NULL);
    737735      aud__exit(FIL__, __LINE__, EXIT_FAILURE);
    738736    }
     
    745743
    746744
    747 static int sh_files_pushfile (int class, char * str_s)
    748 {
     745static int sh_files_pushfile (int class, const char * str_s)
     746{
     747  int     len;
    749748  char  * tmp;
    750   int     len;
     749  char  * p;
    751750#ifdef HAVE_GLOB_H
    752   glob_t  pglob;
    753751  int     globstatus = -1;
    754752  unsigned int     gloop;
     753  glob_t  pglob;
    755754#endif
    756755
     
    808807       * special case of the root directory.
    809808       */
    810       if (str_s[len-1] == '/' && len > 1)
     809      p = sh_util_strdup (str_s);
     810      if (p[len-1] == '/' && len > 1)
    811811        {
    812           str_s[len-1] = '\0';
     812          p[len-1] = '\0';
    813813          --len;
    814814        }
     
    817817
    818818#ifdef HAVE_GLOB_H
    819   if (0 == sh_files_has_metachar(str_s))
    820     {
    821       sh_files_push_file_int (class, str_s, len);
     819  if (0 == sh_files_has_metachar(p))
     820    {
     821      sh_files_push_file_int (class, p, len);
    822822    }
    823823  else
    824824    {
    825825      pglob.gl_offs = 0;
    826       globstatus    = glob (str_s, 0, sh_files_globerr, &pglob);
     826      globstatus    = glob (p, 0, sh_files_globerr, &pglob);
    827827
    828828      if (globstatus == 0 && pglob.gl_pathc > 0)
     
    834834      else
    835835        {
    836           tmp = sh_util_safe_name (str_s);
     836          tmp = sh_util_safe_name (p);
    837837
    838838          if (pglob.gl_pathc == 0
     
    869869
    870870#else
    871   sh_files_push_file_int (class, str_s, len);
    872 #endif
    873 
     871  sh_files_push_file_int (class, p, len);
     872#endif
     873
     874  SH_FREE(p);
    874875  SL_RETURN((0),_("sh_files_pushfile"));
    875876}
     
    10281029}
    10291030
    1030 int sh_files_pushdir_prelink (char * str_s)
     1031int sh_files_pushdir_prelink (const char * str_s)
    10311032{
    10321033  return (sh_files_pushdir (SH_LEVEL_PRELINK, str_s));
    10331034}
    10341035
    1035 int sh_files_pushdir_user0 (char * str_s)
     1036int sh_files_pushdir_user0 (const char * str_s)
    10361037{
    10371038  return (sh_files_pushdir (SH_LEVEL_USER0, str_s));
    10381039}
    10391040
    1040 int sh_files_pushdir_user1 (char * str_s)
     1041int sh_files_pushdir_user1 (const char * str_s)
    10411042{
    10421043  return (sh_files_pushdir (SH_LEVEL_USER1, str_s));
    10431044}
    10441045
    1045 int sh_files_pushdir_attr (char * str_s)
     1046int sh_files_pushdir_attr (const char * str_s)
    10461047{
    10471048  return (sh_files_pushdir (SH_LEVEL_ATTRIBUTES, str_s));
    10481049}
    10491050
    1050 int sh_files_pushdir_ro (char * str_s)
     1051int sh_files_pushdir_ro (const char * str_s)
    10511052{
    10521053  return (sh_files_pushdir (SH_LEVEL_READONLY, str_s));
    10531054}
    10541055
    1055 int sh_files_pushdir_log (char * str_s)
     1056int sh_files_pushdir_log (const char * str_s)
    10561057{
    10571058  return (sh_files_pushdir (SH_LEVEL_LOGFILES, str_s));
    10581059}
    10591060
    1060 int sh_files_pushdir_glog (char * str_s)
     1061int sh_files_pushdir_glog (const char * str_s)
    10611062{
    10621063  return (sh_files_pushdir (SH_LEVEL_LOGGROW, str_s));
    10631064}
    10641065
    1065 int sh_files_pushdir_noig (char * str_s)
     1066int sh_files_pushdir_noig (const char * str_s)
    10661067{
    10671068  return (sh_files_pushdir (SH_LEVEL_NOIGNORE, str_s));
    10681069}
    10691070
    1070 int sh_files_pushdir_allig (char * str_s)
     1071int sh_files_pushdir_allig (const char * str_s)
    10711072{
    10721073  return (sh_files_pushdir (SH_LEVEL_ALLIGNORE, str_s));
     
    11201121      if (tree == NULL)
    11211122        {
    1122           (void) safe_logger (0, 0, getpid());
     1123          (void) safe_logger (0, 0, NULL);
    11231124          aud__exit(FIL__, __LINE__, EXIT_FAILURE);
    11241125        }
     
    11331134  if (-1 == ret)
    11341135    {
    1135       (void) safe_logger (0, 0, getpid());
     1136      (void) safe_logger (0, 0, NULL);
    11361137      aud__exit(FIL__, __LINE__, EXIT_FAILURE);
    11371138    }
     
    11431144}
    11441145
    1145 static int sh_files_pushdir (int class, char * str_s)
     1146static int sh_files_pushdir (int class, const char * str_s)
    11461147{
    11471148  char  * tmp;
     
    11491150  int     rdepth = 0;
    11501151  char  * tail = NULL;
     1152  char  * p;
    11511153
    11521154#ifdef HAVE_GLOB_H
     
    11661168    SL_RETURN((-1), _("sh_files_pushdir"));
    11671169 
    1168 
    1169   if (str_s[0] != '/')
    1170     {
    1171       rdepth = strtol(str_s, &tail, 10);
    1172       if (tail == str_s)
    1173         SL_RETURN((-1), _("sh_files_pushdir"));
     1170  p = sh_util_strdup (str_s);
     1171
     1172  if (p[0] != '/')
     1173    {
     1174      rdepth = strtol(p, &tail, 10);
     1175      if (tail == p)
     1176        {
     1177          SH_FREE(p);
     1178          SL_RETURN((-1), _("sh_files_pushdir"));
     1179        }
    11741180    }
    11751181  else
    1176     tail   = str_s;
     1182    tail   = p;
    11771183 
    11781184
    1179   if (rdepth < (-1) || tail == str_s || rdepth > 99)
     1185  if (rdepth < (-1) || tail == p || rdepth > 99)
    11801186    rdepth = (-2);
    11811187
     
    11881194                       tmp);
    11891195      SH_FREE(tmp);
     1196      SH_FREE(p);
    11901197      SL_RETURN((-1), _("sh_files_pushdir"));
    11911198    }
    11921199  else if (len < 1)
    11931200    {
     1201      SH_FREE(p);
    11941202      SL_RETURN((-1), _("sh_files_pushdir"));
    11951203    }
     
    12001208                       tmp);
    12011209      SH_FREE(tmp);
     1210      SH_FREE(p);
    12021211      SL_RETURN((-1), _("sh_files_pushdir"));
    12031212    }
     
    12681277#endif
    12691278
     1279  SH_FREE(p);
    12701280  SL_RETURN((0), _("sh_files_pushdir"));
    12711281
     
    13221332/* Simply sets our boolean as to whether this check is active
    13231333 */
    1324 int sh_files_check_hardlinks (char * opt)
     1334int sh_files_check_hardlinks (const char * opt)
    13251335{
    13261336  int i;
     
    13381348static struct sh_hle_struct * sh_hl_exc = NULL;
    13391349
    1340 int sh_files_hle_reg (char * str)
     1350int sh_files_hle_reg (const char * str)
    13411351{
    13421352  long   offset;
  • trunk/src/sh_forward.c

    r20 r22  
    345345}
    346346
    347 int sh_forward_setlogserver (char * address)
     347int sh_forward_setlogserver (const char * address)
    348348{
    349349  SL_ENTER(_("sh_forward_setlogserver"));
     
    19111911
    19121912
    1913 int sh_forward_use_clt_class (char * c)
     1913int sh_forward_use_clt_class (const char * c)
    19141914{
    19151915  int i;
     
    19191919}
    19201920
    1921 int sh_forward_use_clt_sev (char * c)
     1921int sh_forward_use_clt_sev (const char * c)
    19221922{
    19231923  int i;
     
    19501950}
    19511951
    1952 extern int safe_logger (int signal, int method, pid_t thepid);
    1953 
    1954 int sh_forward_register_client (char * str)
     1952
     1953int sh_forward_register_client (const char * str)
    19551954{
    19561955  client_t   * newclt;
    19571956  client_t   * testclt;
    19581957
    1959   char      * ptr;
     1958  const char * ptr;
    19601959  int          sepnum = 0;
    19611960  int          sep[2];
     
    19801979      if (all_clients == NULL)
    19811980        {
    1982           (void) safe_logger (0, 0, getpid());
     1981          (void) safe_logger (0, 0, NULL);
    19831982          aud__exit(FIL__, __LINE__, EXIT_FAILURE);
    19841983        }
     
    20122011        newclt->status_arr[i] = CLT_INACTIVE;
    20132012      sl_strlcpy(newclt->timestamp[CLT_INACTIVE],   sh_unix_time(0), TIM_MAX);
     2013      /* truncate */
    20142014      sl_strlcpy(newclt->hostname,  &str[0],        sep[0]+1);
     2015      /* truncate */
    20152016      sl_strlcpy(newclt->salt,      &str[sep[0]+1], sep[1]-sep[0]);
    20162017      sl_strlcpy(newclt->verifier,  &str[sep[1]+1], sl_strlen(str)-sep[1]+1);
     
    23862387
    23872388#if defined(WITH_EXTERNAL)
    2388   sprintf(msg, _("%s %s %s"),                       /* known to fit  */
    2389           conn->hostname,
    2390           conn->timestamp[status],
    2391           _(clt_stat[status]));
     2389  sl_snprintf(msg, sizeof(msg), _("%s %s %s"),
     2390              conn->hostname, conn->timestamp[status], _(clt_stat[status]));
    23922391  sh_ext_execute('s', 'r', 'v', msg, 0);
    23932392#endif
     
    23982397static time_t time_client_limit = 86400;
    23992398
    2400 int sh_forward_set_time_limit (char * c)
     2399int sh_forward_set_time_limit (const char * c)
    24012400{
    24022401  long val;
     
    24482447static int lookup_err = SH_ERR_SEVERE;
    24492448
    2450 int sh_forward_lookup_level (char * c)
     2449int sh_forward_lookup_level (const char * c)
    24512450{
    24522451  int ci =  sh_error_convert_level (c);
     
    26032602static int UseSocketPeer = S_FALSE;
    26042603
    2605 int set_socket_peer (char * c)
     2604int set_socket_peer (const char * c)
    26062605{
    26072606  return sh_util_flagval(c, &UseSocketPeer);
     
    27312730  char       hash[SH_MAXMSGLEN + KEY_LEN + KEY_LEN + 1];
    27322731  char     * buffer;
    2733   long       len;
    27342732
    27352733  int        clt_sev;
     
    27372735
    27382736  UINT32     ticks;
     2737  size_t     len;
    27392738  int        i;
    27402739  char     * test;
     
    28212820                    sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_FAUTH,
    28222821                                    &(conn->buf[KEY_LEN]));
    2823                   strcpy(conn->buf,                      /* known to fit  */
    2824                          &(conn->buf[KEY_LEN]));
     2822                  len = sl_strlen(&(conn->buf[KEY_LEN])) + 1;
     2823                  /* &(conn->buf[KEY_LEN]) is hostname         */
     2824                  /* may overlap, thus only memmove is correct */
     2825                  memmove(conn->buf, &(conn->buf[KEY_LEN]), len);
    28252826                  this_client->session_key[0]    = '\0';
    28262827                  this_client->session_key_timer = (time_t) 1;
     
    28352836                  conn->K = NULL;
    28362837                }
    2837               i = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1;
    2838               conn->K = SH_ALLOC(i);
     2838              len = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1;
     2839              conn->K = SH_ALLOC(len);
    28392840
    28402841              sl_strlcpy (conn->K,
     
    29142915              conn->A = SH_ALLOC(3*KEY_LEN+1);
    29152916              sl_strlcpy (conn->A, conn->K, KEY_LEN+1);
    2916               sl_strlcat(conn->A, conn->buf, /* ignore remainder */
     2917              sl_strlcat(conn->A, conn->buf, /* truncate */
    29172918                         2*KEY_LEN+1);
    29182919              sl_strlcat(conn->A, conn->client_entry->session_key,
     
    32783279                    sh_error_handle((-1), FIL__, __LINE__, 0, MSG_TCP_FAUTH,
    32793280                                    &(conn->buf[KEY_LEN]));
    3280                   strcpy(conn->buf,                      /* known to fit  */
    3281                          &(conn->buf[KEY_LEN]));
     3281                  len = sl_strlen(&(conn->buf[KEY_LEN])) + 1;
     3282                  /* &(conn->buf[KEY_LEN]) is hostname         */
     3283                  /* may overlap, thus only memmove is correct */
     3284                  memmove(conn->buf, &(conn->buf[KEY_LEN]), len);
    32823285                  this_client->session_key[0]    = '\0';
    32833286                  this_client->session_key_timer = (time_t) 1;
     
    32933296                  conn->K = NULL;
    32943297                }
    3295               i = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1;
    3296               conn->K = SH_ALLOC(i);
     3298              len = sl_strlen(&(conn->buf[KEY_LEN])) + KEY_LEN + 1;
     3299              conn->K = SH_ALLOC(len);
    32973300
    32983301              sl_strlcpy (conn->K,
     
    46004603static unsigned int server_port = SH_DEFAULT_PORT;
    46014604
    4602 int sh_forward_set_port (char * str)
     4605int sh_forward_set_port (const char * str)
    46034606{
    46044607  int retval = 0;
    46054608  unsigned long   i;
    4606   char * endptr = str;
     4609  char * endptr;
    46074610 
    46084611  SL_ENTER(_("sh_forward_set_port"));
     
    46214624static int            use_server_interface = 0;
    46224625
    4623 int sh_forward_set_interface (char * str)
     4626int sh_forward_set_interface (const char * str)
    46244627{
    46254628  if (0 == strcmp(str, _("INADDR_ANY")))
     
    48144817   */
    48154818  new_act.sa_handler = SIG_IGN;
     4819  sigemptyset( &new_act.sa_mask );         /* set an empty mask       */
     4820  new_act.sa_flags = 0;                    /* init sa_flags           */
    48164821  retry_sigaction (FIL__, __LINE__, SIGPIPE, &new_act, &old_act);
    48174822
     
    55715576}
    55725577
    5573 int set_syslog_active(char * c)
     5578int set_syslog_active(const char * c)
    55745579{
    55755580  return sh_util_flagval(c, &enable_syslog_socket);
  • trunk/src/sh_getopt.c

    r20 r22  
    391391    if (op_table[i].hasArg == HAS_ARG_NO) {
    392392      if (sl_strlen(op_table[i].longopt) < 10)
    393         strcpy(fmt,_("%c%c%c        --%-s,\t\t\t %s\n"));/* known to fit  */
     393        sl_strlcpy(fmt,_("%c%c%c        --%-s,\t\t\t %s\n"), sizeof(fmt));
    394394      else if (sl_strlen(op_table[i].longopt) < 17)
    395         strcpy(fmt, _("%c%c%c        --%-s,\t\t %s\n")); /* known to fit  */
     395        sl_strlcpy(fmt, _("%c%c%c        --%-s,\t\t %s\n"), sizeof(fmt));
    396396      else
    397         strcpy(fmt, _("%c%c%c        --%-s,\t %s\n"));   /* known to fit  */
    398       /*@-formatconst@*/
    399       fprintf (stdout,
    400                fmt,
     397        sl_strlcpy(fmt, _("%c%c%c        --%-s,\t %s\n"), sizeof(fmt));
     398      /* flawfinder: ignore */
     399      fprintf (stdout, fmt,
    401400               (op_table[i].shortopt == '-') ? ' ' : '-',
    402401               (op_table[i].shortopt == '-') ? ' ' : op_table[i].shortopt,
     
    404403               _(op_table[i].longopt),
    405404               _(op_table[i].usage));
    406       /*@+formatconst@*/
    407405    } else {
    408406      if (sl_strlen(op_table[i].longopt) < 12)
    409         strcpy(fmt,                                      /* known to fit  */
    410                _("%c%c %s  --%-s=<arg>,\t\t %s\n")); 
     407        sl_strlcpy(fmt, _("%c%c %s  --%-s=<arg>,\t\t %s\n"), sizeof(fmt)); 
    411408      else
    412         strcpy(fmt,                                      /* known to fit  */
    413                _("%c%c %s  --%-s=<arg>,\t %s\n"));   
    414       /*@-formatconst@*/
    415       fprintf (stdout,
    416                fmt,
     409        sl_strlcpy(fmt, _("%c%c %s  --%-s=<arg>,\t %s\n"), sizeof(fmt));   
     410      /* flawfinder: ignore */
     411      fprintf (stdout, fmt,
    417412               (op_table[i].shortopt == '-') ? ' ' : '-',
    418413               (op_table[i].shortopt == '-') ? ' ' : op_table[i].shortopt,
     
    420415               _(op_table[i].longopt),
    421416               _(op_table[i].usage));
    422       /*@+formatconst@*/
    423417    }
    424418  }
  • trunk/src/sh_gpg.c

    r1 r22  
    209209  FILE * outf = NULL;
    210210  char * envp[2];
     211  size_t len;
    211212  char   path[256];
    212213  char   cc1[32];
     
    370371  if (sh.effective.home != NULL)
    371372    {
    372       envp[0] = malloc (sl_strlen(sh.effective.home) + 6); /* free() ok   */
     373      len = sl_strlen(sh.effective.home) + 6;
     374      envp[0] = malloc (len); /* free() ok   */
    373375      if (envp[0] != NULL)
    374         sprintf (envp[0], "HOME=%s",                     /* known to fit  */
    375                  sh.effective.home);
     376        sl_snprintf (envp[0], len, "HOME=%s", sh.effective.home);
    376377      envp[1] = NULL;
    377378    }
     
    486487
    487488      pfd = get_the_fd(checkfd);
    488       sprintf(pname, _("/proc/self/fd/%d"),             /* known to fit  */
    489                    pfd);
    490       if (0 == access(pname, R_OK|X_OK))
     489      sl_snprintf(pname, sizeof(pname), _("/proc/self/fd/%d"), pfd);
     490      if (0 == access(pname, R_OK|X_OK))               /* flawfinder: ignore */
     491
    491492        {
    492493          fcntl  (pfd, F_SETFD, FD_CLOEXEC);
  • trunk/src/sh_hash.c

    r20 r22  
    12681268}
    12691269
    1270 int sh_hash_version_string(char * str)
     1270int sh_hash_version_string(const char * str)
    12711271{
    12721272  int i;
  • trunk/src/sh_html.c

    r1 r22  
    296296            {
    297297              entry_orig = realloc(entry_orig,           /* free() ok     */
    298                                    entry_size + line_size);
     298                                   entry_size + line_size + 1);
    299299              if (entry_orig) { add_size = line_size; }
    300300            }
     
    302302            {
    303303              entry_orig = malloc(line_size + 1);        /* free() ok     */
    304               if (entry_orig) { entry_orig[0] = '\0'; add_size = line_size + 1; }
     304              if (entry_orig) { entry_orig[0] = '\0'; add_size = line_size; }
    305305            }
    306306          if (!entry_orig)
     
    311311            }
    312312
    313           strcat(&entry_orig[entry_size], line);         /* known to fit  */
     313          sl_strlcat(&entry_orig[entry_size], line, line_size + 1);
    314314          entry_size += add_size;
     315          SH_VAL_EQ(entry_orig[entry_size], '\0');
    315316        }
    316317      sl_close(fd);
  • trunk/src/sh_ignore.c

    r1 r22  
    5353
    5454static struct sh_ignore_list * sh_ignore_add_int(struct sh_ignore_list * list,
    55                                                  char * addpath)
     55                                                 const char * addpath)
    5656{
    5757  struct sh_ignore_list * new;
     
    9696}
    9797
    98 int sh_ignore_add_del (char * addpath)
     98int sh_ignore_add_del (const char * addpath)
    9999{
    100100  if ((addpath == NULL) || (addpath[0] != '/'))
     
    106106}
    107107
    108 int sh_ignore_add_new (char * addpath)
     108int sh_ignore_add_new (const char * addpath)
    109109{
    110110  if ((addpath == NULL) || (addpath[0] != '/'))
  • trunk/src/sh_kern.c

    r3 r22  
    431431  int (*rename) (int *, int *,
    432432                 int *, int *);
     433  /* flawfinder: ignore */
    433434  int (*readlink) (int *, char *,int);
    434435  int (*follow_link) (int *, int *);
  • trunk/src/sh_mail.c

    r20 r22  
    271271
    272272static
    273 int sh_filter_filteradd (char * argstring, sh_filter_type * filter, int ftype)
     273int sh_filter_filteradd (const char * argstring,
     274                         sh_filter_type * filter, int ftype)
    274275{
    275276  int     i = 0;
     
    372373 */
    373374static
    374 int sh_filter_filter (char * message, sh_filter_type * filter)
     375int sh_filter_filter (const char * message, sh_filter_type * filter)
    375376{
    376377  int i;
     
    432433 * -- add keywords to the OR filter
    433434 */
    434 int sh_mail_add_or (char * str)
     435int sh_mail_add_or (const char * str)
    435436{
    436437  return (sh_filter_filteradd (str, &(mail_filter), SH_FILT_OR));
     
    440441 * -- add keywords to the AND filter
    441442 */
    442 int sh_mail_add_and (char * str)
     443int sh_mail_add_and (const char * str)
    443444{
    444445  return (sh_filter_filteradd (str, &(mail_filter), SH_FILT_AND));
     
    448449 * -- add keywords to the NOT filter
    449450 */
    450 int sh_mail_add_not (char * str)
     451int sh_mail_add_not (const char * str)
    451452{
    452453  return (sh_filter_filteradd (str, &(mail_filter), SH_FILT_NOT));
     
    473474}
    474475
    475 int sh_mail_setaddress (char * address)
     476int sh_mail_setaddress (const char * address)
    476477{
    477478  char     *     p;
     
    523524}
    524525
    525 int sh_mail_setaddress_int (char * address)
     526int sh_mail_setaddress_int (const char * address)
    526527{
    527528  int i;
     
    533534}
    534535
    535 int sh_mail_setNum (char * str)
     536int sh_mail_setNum (const char * str)
    536537{
    537538  int i = atoi (str);
     
    549550static int all_in_one = S_FALSE;
    550551
    551 int sh_mail_setFlag (char * str)
     552int sh_mail_setFlag (const char * str)
    552553{
    553554  int i;
     
    559560static char * mail_subject = NULL;
    560561
    561 int set_mail_subject (char * str)
     562int set_mail_subject (const char * str)
    562563{
    563564  SL_ENTER(_("set_mail_subject"));
     
    10061007        /* reveal first signature key
    10071008         */
    1008         (void) sl_strlcpy(skey->crypt, skey->mailkey_new, KEY_LEN+1);
     1009        /* flawfinder: ignore */
     1010        (void) sl_strlcpy(skey->crypt, skey->mailkey_new, KEY_LEN+1);
    10091011
    10101012        BREAKEXIT(sh_util_encode);
     1013        /* flawfinder: ignore */
    10111014        sh_util_encode(skey->crypt, bufcompress, 0, 'A');
    10121015
     1016        /* flawfinder: ignore */
    10131017        (void) sl_strlcat (mailMsg, skey->crypt, msgbufsize);
     1018        /* flawfinder: ignore */
    10141019        memset (skey->crypt, 0, KEY_LEN);
    10151020        isfirst = 0;
     
    10211026    (void) sl_strlcpy (skey->mailkey_old, skey->mailkey_new, KEY_LEN+1);
    10221027
    1023     /*@-bufferoverflowhigh@*/
    1024     sprintf(subject, _("%06d %010ld::%s\r\n"),         /* known to fit  */
    1025             mailcount, (long) id_audit, sh.host.name);
    1026     /*@+bufferoverflowhigh@*/
     1028    sl_snprintf(subject, sizeof(subject), _("%06d %010ld::%s\r\n"),
     1029                mailcount, (long) id_audit, sh.host.name);
    10271030
    10281031    (void) sl_strlcat (mailMsg, subject, msgbufsize);
     
    12221225static char * relay_host = NULL;
    12231226
    1224 int sh_mail_set_relay (char * str_s)
     1227int sh_mail_set_relay (const char * str_s)
    12251228{
    12261229  size_t i = 0;
     
    12511254static char * mail_sender = NULL;
    12521255
    1253 int sh_mail_set_sender (char *str)
     1256int sh_mail_set_sender (const char *str)
    12541257{
    12551258  if (mail_sender != NULL)
     
    17351738      if (g != 1)
    17361739        {
    1737           /*@-bufferoverflowhigh@*/
    1738           sprintf(errmsg,                              /* known to fit  */
    1739                   _("Bad response (%d), expected %d"), rcode, code);
    1740           /*@+bufferoverflowhigh@*/
     1740          sl_snprintf(errmsg, sizeof(errmsg),
     1741                      _("Bad response (%d), expected %d"), rcode, code);
     1742
    17411743          sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET,
    17421744                          errmsg, _("sh_mail_wait"),
     
    18831885  int  ret, length, status;
    18841886  mx * result;
     1887  size_t len;
    18851888
    18861889  typedef union
     
    20652068       */
    20662069      result[count].pref = pref;
    2067       result[count].address = SH_ALLOC (strlen (expanded) + 1);
    2068       strcpy (result[count].address, expanded);        /* known to fit  */
     2070      len = strlen (expanded) + 1;
     2071      result[count].address = SH_ALLOC (len);
     2072      sl_strlcpy (result[count].address, expanded, len);
    20692073    }
    20702074  while (ret > 0 && comp_dn < eom && count);
     
    21012105  mx     * result;
    21022106  dnsrep * retval;
    2103   char     errmsg[128];
     2107  char     errmsg[128];
     2108  size_t   len;
    21042109
    21052110  SL_ENTER(_("return_mx"));
     
    21282133                           _("get_mx"));
    21292134#else
     2135          /* flawfinder: ignore *//* test code only */
    21302136          strcpy  (errmsg,                               /* known to fit  */
    21312137                   _("No MX record for domain "));
     
    21552161      result->pref  = 0;
    21562162      /*@-type@*/
    2157       result->address = SH_ALLOC (strlen (host->h_name) + 1);
    2158       strcpy (result->address, host->h_name);          /* known to fit  */
     2163      len = strlen (host->h_name) + 1;
     2164      result->address = SH_ALLOC (len);
     2165      sl_strlcpy (result->address, host->h_name, len);
    21592166      /*@+type@*/
    21602167      SL_RETURN (retval, _("return_mx"));
  • trunk/src/sh_mem.c

    r11 r22  
    3939#include "sh_mem.h"
    4040
    41 extern int safe_logger (int signal, int method, pid_t thepid);
     41extern int safe_logger (int signal, int method, char * details);
    4242
    4343#undef  FIL__
     
    228228        {
    229229          eblock = 1;
    230           (void) safe_logger (0, 0, getpid());
     230          (void) safe_logger (0, 0, NULL);
    231231          /*
    232232          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_MMEM,
     
    320320        {
    321321          eblock = 1;
    322           (void) safe_logger(0, 0, getpid());
     322          (void) safe_logger(0, 0, NULL);
    323323          /*
    324324          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_MMEM,
     
    456456        {
    457457          eblock = 1;
    458           (void) safe_logger(0, 0, getpid());
     458          (void) safe_logger(0, 0, NULL);
    459459          /*
    460460          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_E_MMEM);
  • trunk/src/sh_prelink.c

    r8 r22  
    3838static char * prelink_hash = NULL;
    3939
    40 int sh_prelink_set_path (char * str)
     40int sh_prelink_set_path (const char * str)
    4141{
    4242  size_t len;
     
    5555}
    5656
    57 int sh_prelink_set_hash (char * str)
     57int sh_prelink_set_hash (const char * str)
    5858{
    5959  size_t len;
     
    245245  sl_read_timeout_prep (task.pipeTI);
    246246
    247   strcpy(file_hash,                        /* known to fit */
    248          sh_tiger_generic_hash (path, TIGER_FD, 0, alert_timeout));
     247  sl_strlcpy(file_hash,
     248             sh_tiger_generic_hash (path, TIGER_FD, 0, alert_timeout),
     249             KEY_LEN+1);
    249250
    250251  /* restore old signal handler
  • trunk/src/sh_prelude.c

    r20 r22  
    133133}
    134134
    135 static int set_prelude_severity_int (char * str, int prelude_sev)
    136 {
    137         char * p = strtok (str, ", \t");
     135static int set_prelude_severity_int (const char * str, int prelude_sev)
     136{
     137        char * p;
     138        char * dup = strdup (str);
     139
     140        p = strtok (dup, ", \t");
    138141
    139142        if (p) {
     
    160163                } while (p);
    161164        }
     165        free(dup);
    162166        return 0;
    163167}
    164168
    165 int sh_prelude_map_info (char * str)
     169int sh_prelude_map_info (const char * str)
    166170{
    167171        return (set_prelude_severity_int(str,(int)IDMEF_IMPACT_SEVERITY_INFO));
    168172}
    169 int sh_prelude_map_low (char * str)
     173int sh_prelude_map_low (const char * str)
    170174{
    171175        return (set_prelude_severity_int(str,(int)IDMEF_IMPACT_SEVERITY_LOW));
    172176}
    173 int sh_prelude_map_medium (char * str)
     177int sh_prelude_map_medium (const char * str)
    174178{
    175179        return (set_prelude_severity_int(str,(int)IDMEF_IMPACT_SEVERITY_MEDIUM));
    176180}
    177 int sh_prelude_map_high (char * str)
     181int sh_prelude_map_high (const char * str)
    178182{
    179183        return (set_prelude_severity_int(str,(int)IDMEF_IMPACT_SEVERITY_HIGH));
     
    300304}
    301305
     306/* flawfinder: ignore *//* is part of name, not access() */
    302307static void get_access_info(idmef_file_access_t *access, char * mode, int pos, int mpos)
    303308{
     
    308313        do {
    309314                if ( mode[pos] == 'r' ) {
     315                        /* flawfinder: ignore *//* is part of name, not access() */
    310316                        ret = idmef_file_access_new_permission(access, &str, -1);
    311317                        if ( ret < 0 )
     
    315321                }
    316322                else if ( mode[pos] == 'w' ) {
     323                        /* flawfinder: ignore *//* is part of name, not access() */
    317324                        ret = idmef_file_access_new_permission(access, &str, -1);
    318325                        if ( ret < 0 )
     
    322329                }
    323330                else if ( mode[pos] == 'x' || mode[pos] == 's' || mode[pos] == 't') {
     331                        /* flawfinder: ignore *//* is part of name, not access() */
    324332                        ret = idmef_file_access_new_permission(access, &str, -1);
    325333                        if ( ret < 0 )
     
    340348
    341349        if ( got == 0 ) {
     350                /* flawfinder: ignore *//* is part of name, not access() */
    342351                ret = idmef_file_access_new_permission(access, &str, -1);
    343352                if ( ret < 0 )
     
    360369        prelude_string_t *str;
    361370        idmef_checksum_t *checksum;
    362         idmef_file_access_t *access;
     371        idmef_file_access_t *access; /* flawfinder: ignore */
    363372        idmef_user_id_t *userid;
    364373        const char *suffix = (category == IDMEF_FILE_CATEGORY_CURRENT) ? "_new" : "_old";
     
    459468        mode = get_value(msg, _("mode"), suffix);
    460469        if ( mode ) {
     470                /* flawfinder: ignore *//* is part of name, not access() */
    461471                ret = idmef_file_new_file_access(file, &access, -1);
    462472                if ( ret < 0 )
    463473                        return;
    464474
     475                /* flawfinder: ignore *//* is part of name, not access() */
    465476                ret = idmef_file_access_new_user_id(access, &userid);
    466477                if ( ret < 0 )
     
    468479                idmef_user_id_set_type(userid, IDMEF_USER_ID_TYPE_OTHER_PRIVS);
    469480
     481                /* flawfinder: ignore *//* is part of name, not access() */
    470482                get_access_info ( access, mode, 7, 9 );
    471483        }
     
    475487                struct passwd *pw;
    476488               
     489                /* flawfinder: ignore *//* is part of name, not access() */
    477490                ret = idmef_file_new_file_access(file, &access, 0);
    478491                if ( ret < 0 )
    479492                        return;
    480493
     494                /* flawfinder: ignore *//* is part of name, not access() */
    481495                ret = idmef_file_access_new_user_id(access, &userid);
    482496                if ( ret < 0 )
     
    497511
    498512                if ( mode ) {
     513                        /* flawfinder: ignore *//* is part of name, not access() */
    499514                        get_access_info ( access, mode, 1, 3 );
    500515                }
     
    505520                struct group *gr;
    506521               
     522                /* flawfinder: ignore *//* is part of name, not access() */
    507523                ret = idmef_file_new_file_access(file, &access, -1);
    508524                if ( ret < 0 )
    509525                        return;
    510526
     527                /* flawfinder: ignore *//* is part of name, not access() */
    511528                ret = idmef_file_access_new_user_id(access, &userid);
    512529                if ( ret < 0 )
     
    527544
    528545                if ( mode ) {
    529                         get_access_info ( access, mode, 4, 6 );
     546                        get_access_info ( access, mode, 4, 6 ); /* flawfinder: ignore */
    530547                }
    531548        }
     
    890907
    891908
    892 int sh_prelude_set_profile(char *arg)
     909int sh_prelude_set_profile(const char *arg)
    893910{
    894911        if ( profile ) {
  • trunk/src/sh_readconf.c

    r20 r22  
    5252#endif
    5353
    54 extern int set_reverse_lookup (char * c);
     54extern int set_reverse_lookup (const char * c);
    5555
    5656#undef  FIL__
     
    282282  /* The system type, release, and machine.
    283283   */
    284   sprintf(myident, _("%s:%s:%s"),                  /* known to fit  */
    285           sh.host.system, sh.host.release, sh.host.machine);
     284  sl_snprintf(myident, sizeof(myident), _("%s:%s:%s"), 
     285              sh.host.system, /* flawfinder: ignore */
     286              sh.host.release, sh.host.machine);
    286287
    287288
     
    580581}
    581582
    582 int sh_readconf_set_path (char * which, char * what)
     583int sh_readconf_set_path (char * which, const char * what)
    583584{
    584585  int len;
     
    621622}
    622623
    623 int sh_readconf_set_database_path (char * what)
     624int sh_readconf_set_database_path (const char * what)
    624625{
    625626  return (sh_readconf_set_path(sh.data.path, what));
    626627}
    627628
    628 int sh_readconf_set_logfile_path (char * what)
     629int sh_readconf_set_logfile_path (const char * what)
    629630{
    630631  return (sh_readconf_set_path(sh.srvlog.name, what));
    631632}
    632633
    633 int sh_readconf_set_lockfile_path (char * what)
     634int sh_readconf_set_lockfile_path (const char * what)
    634635{
    635636  return( sh_readconf_set_path(sh.srvlog.alt, what));
     
    645646 
    646647   
    647 int sh_readconf_setTime (char * str, ShTimerItem what)
     648int sh_readconf_setTime (const char * str, ShTimerItem what)
    648649{
    649650  unsigned long i = atoi (str);
     
    674675}
    675676
    676 int sh_readconf_setMailtime (char * c)
     677int sh_readconf_setMailtime (const char * c)
    677678{
    678679  return sh_readconf_setTime (c, SET_MAILTIME);
    679680}
    680681
    681 int sh_readconf_setFiletime (char * c)
     682int sh_readconf_setFiletime (const char * c)
    682683{
    683684  return sh_readconf_setTime (c, SET_FILETIME);
    684685}
    685686
    686 int sh_readconf_set_nice (char * c)
     687int sh_readconf_set_nice (const char * c)
    687688{
    688689  long val;
     
    704705
    705706#ifdef FANCY_LIBCAP
    706 int sh_readconf_setCaps(char * c)
     707int sh_readconf_setCaps(const char * c)
    707708{
    708709  int i;
     
    718719  ShSectionType   section;
    719720  ShSectionType   alt_section;
    720   int (*func)(char * opt);
     721  int (*func)(const char * opt);
    721722} cfg_options;
    722723
    723724#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
    724 extern int sh_set_schedule_one(char * str);
    725 extern int sh_set_schedule_two(char * str);
     725extern int sh_set_schedule_one(const char * str);
     726extern int sh_set_schedule_two(const char * str);
    726727#endif
    727728#if defined (SH_WITH_SERVER)
    728 extern int sh_socket_use (char * c);
    729 extern int sh_socket_uid (char * c);
    730 extern int sh_socket_password (char * c);
    731 #endif
    732 
    733 /* Yes, this isn't very elegant ;)
    734  */
    735 #if defined(WITH_EXTERNAL)
    736 int sh_error_set_external_wrap (char * str) {
    737   return sh_error_set_external ((const char *) str);
    738 }
    739 #endif
    740 #if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
    741 int sh_files_setrecursion_wrap (char * str) {
    742   return sh_files_setrecursion ((const char *) str);
    743 }
    744 int sh_util_setchecksum_wrap (char * str) {
    745   return sh_util_setchecksum ((const char *) str);
    746 }
    747 #endif
    748 int sh_util_setlooptime_wrap (char * str) {
    749   return sh_util_setlooptime ((const char *) str);
    750 }
    751 #ifdef SH_WITH_MAIL
    752 int sh_error_setseverity_wrap (char * str) {
    753   return sh_error_setseverity ((const char *) str);
    754 }
    755 #endif
    756 int sh_calls_set_bind_addr_wrap (char * str) {
    757   return sh_calls_set_bind_addr ((const char *) str);
    758 }
    759 int sh_unix_setdeamon_wrap (char * str) {
    760   return sh_unix_setdeamon ((const char *) str);
    761 }
    762 int sh_error_setprint_wrap (char * str) {
    763   return sh_error_setprint ((const char *) str);
    764 }
    765 int sh_error_setlog_wrap (char * str) {
    766   return sh_error_setlog ((const char *) str);
    767 }
    768 int sh_error_set_syslog_wrap (char * str) {
    769   return sh_error_set_syslog ((const char *) str);
    770 }
    771 #ifdef HAVE_LIBPRELUDE
    772 int sh_error_set_prelude_wrap (char * str) {
    773   return sh_error_set_prelude ((const char *) str);
    774 }
    775 #endif
    776 #ifdef SH_WITH_CLIENT
    777 int sh_error_setexport_wrap (char * str) {
    778   return sh_error_setexport ((const char *) str);
    779 }
    780 #endif
    781 #ifdef SH_WITH_SERVER
    782 int sh_forward_set_strip_wrap (char * str) {
    783   return sh_forward_set_strip ((const char *) str);
    784 }
    785 int sh_unix_set_chroot_wrap (char * str) {
    786   return sh_unix_set_chroot ((const char *) str);
    787 }
    788 #endif
    789 #if defined(WITH_DATABASE)
    790 int sh_error_set_database_wrap (char * str) {
    791   return sh_error_set_database ((const char *) str);
    792 }
    793 #endif
    794  
     729extern int sh_socket_use (const char * c);
     730extern int sh_socket_uid (const char * c);
     731extern int sh_socket_password (const char * c);
     732#endif
     733
    795734cfg_options ext_table[] = {
    796735#if defined(WITH_EXTERNAL)
     
    818757    sh_ext_add_or },
    819758  { N_("externalseverity"),SH_SECTION_LOG,      SH_SECTION_EXTERNAL, 
    820     sh_error_set_external_wrap },
     759    sh_error_set_external },
    821760  { N_("externalclass"),   SH_SECTION_LOG,      SH_SECTION_EXTERNAL, 
    822761    sh_error_external_mask },
     
    845784    set_enter_wrapper },
    846785#endif
     786
    847787
    848788#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
     
    902842    sh_util_obscure_ok },
    903843  { N_("setrecursionlevel"),  SH_SECTION_MISC,   SH_SECTION_NONE,
    904     sh_files_setrecursion_wrap },
     844    sh_files_setrecursion },
    905845  { N_("checksumtest"),       SH_SECTION_MISC,   SH_SECTION_NONE,
    906     sh_util_setchecksum_wrap },
     846    sh_util_setchecksum },
    907847  { N_("reportonlyonce"),     SH_SECTION_MISC,   SH_SECTION_NONE,
    908848    sh_files_reportonce },
     
    961901  { N_("setprelinkchecksum"),   SH_SECTION_MISC,   SH_SECTION_NONE,
    962902    sh_prelink_set_hash },
     903
    963904  /* client or standalone
    964905   */
     
    977918    sh_socket_password },
    978919  { N_("setstripdomain"),      SH_SECTION_SRV,  SH_SECTION_MISC,
    979     sh_forward_set_strip_wrap },
     920    sh_forward_set_strip },
    980921  { N_("useseparatelogs"),     SH_SECTION_SRV,  SH_SECTION_MISC,
    981922    set_flag_sep_log },
    982923  { N_("setchrootdir"),        SH_SECTION_SRV,  SH_SECTION_MISC,
    983     sh_unix_set_chroot_wrap },
     924    sh_unix_set_chroot },
    984925  { N_("setclienttimelimit"),  SH_SECTION_SRV,  SH_SECTION_MISC,
    985926    sh_forward_set_time_limit },
     
    1002943#ifdef SH_WITH_CLIENT
    1003944  { N_("exportseverity"),      SH_SECTION_LOG,  SH_SECTION_NONE,
    1004     sh_error_setexport_wrap },
     945    sh_error_setexport },
    1005946  { N_("exportclass"),         SH_SECTION_LOG,  SH_SECTION_NONE,
    1006947    sh_error_export_mask },
     
    1011952    sh_readconf_setFiletime },
    1012953  { N_("setlooptime"),     SH_SECTION_MISC,  SH_SECTION_NONE,
    1013     sh_util_setlooptime_wrap },
     954    sh_util_setlooptime },
    1014955
    1015956#ifdef SH_WITH_MAIL
    1016957  { N_("mailseverity"),      SH_SECTION_LOG,   SH_SECTION_NONE,
    1017     sh_error_setseverity_wrap },
     958    sh_error_setseverity },
    1018959  { N_("mailclass"),         SH_SECTION_LOG,   SH_SECTION_NONE,
    1019960    sh_error_mail_mask },
     
    1040981#endif
    1041982  { N_("setbindaddress"),    SH_SECTION_MISC,  SH_SECTION_NONE,
    1042     sh_calls_set_bind_addr_wrap },
     983    sh_calls_set_bind_addr },
    1043984  { N_("daemon"),            SH_SECTION_MISC,  SH_SECTION_NONE,
    1044     sh_unix_setdeamon_wrap },
     985    sh_unix_setdeamon },
    1045986  { N_("samhainpath"),       SH_SECTION_MISC,  SH_SECTION_NONE,
    1046987    sh_unix_self_hash },
     
    1051992
    1052993  { N_("printseverity"),     SH_SECTION_LOG,   SH_SECTION_NONE,
    1053     sh_error_setprint_wrap },
     994    sh_error_setprint },
    1054995  { N_("printclass"),        SH_SECTION_LOG,   SH_SECTION_NONE,
    1055996    sh_error_print_mask },
    1056997
    1057998  { N_("logseverity"),       SH_SECTION_LOG,   SH_SECTION_NONE,
    1058     sh_error_setlog_wrap },
     999    sh_error_setlog },
    10591000  { N_("logclass"),          SH_SECTION_LOG,   SH_SECTION_NONE,
    10601001    sh_error_log_mask },
    10611002
    10621003  { N_("syslogseverity"),    SH_SECTION_LOG,   SH_SECTION_NONE,
    1063     sh_error_set_syslog_wrap },
     1004    sh_error_set_syslog },
    10641005  { N_("syslogclass"),       SH_SECTION_LOG,   SH_SECTION_NONE,
    10651006    sh_error_syslog_mask },
    10661007#ifdef HAVE_LIBPRELUDE
    10671008  { N_("preludeseverity"),   SH_SECTION_LOG,   SH_SECTION_NONE,
    1068     sh_error_set_prelude_wrap },
     1009    sh_error_set_prelude },
    10691010  { N_("preludeclass"),      SH_SECTION_LOG,   SH_SECTION_NONE,
    10701011    sh_error_prelude_mask },
  • trunk/src/sh_schedule.c

    r1 r22  
    5353#endif
    5454
     55#include "samhain.h"
    5556#include "sh_mem.h"
    5657
     
    318319  char * copy;
    319320  int    i = 0;
     321  size_t len;
    320322
    321323  if (!ssched || !isched)
    322324    return -1;
    323325
     326  len = strlen(ssched)+1;
    324327#ifdef TESTONLY
    325   copy = malloc(strlen(ssched)+1);                 /* testonly code */
    326 #else
    327   copy = SH_ALLOC(strlen(ssched)+1);
    328 #endif
    329   strcpy(copy, ssched);                            /* known to fit  */
     328  copy = malloc(len);                 /* testonly code */
     329#else
     330  copy = SH_ALLOC(len);
     331#endif
     332  sl_strlcpy(copy, ssched, len);
    330333
    331334  p = strtok(copy, " \t"); /* parse crontab-style schedule */
  • trunk/src/sh_socket.c

    r1 r22  
    244244}
    245245
    246 int sh_socket_use (char * c)
     246int sh_socket_use (const char * c)
    247247{
    248248  return sh_util_flagval(c, &sh_socket_flaguse);
     
    289289#endif
    290290
    291 int sh_socket_uid (char * c)
     291int sh_socket_uid (const char * c)
    292292{
    293293  uid_t val = (uid_t) strtol (c, (char **)NULL, 10);
     
    301301}
    302302
    303 int sh_socket_password (char * c)
     303int sh_socket_password (const char * c)
    304304{
    305305#if defined(NEED_PASSWORD_AUTH)
     
    378378
    379379  name.sun_family = AF_FILE;
    380   strcpy (name.sun_path, sh_sockname);
     380  sl_strlcpy (name.sun_path, sh_sockname, sizeof(name.sun_path));
    381381
    382382  size = (offsetof (struct sockaddr_un, sun_path)
     
    878878
    879879  new = SH_ALLOC(sizeof(struct socket_cmd));
    880   strcpy (new->cmd, in->cmd);
    881   strcpy (new->clt, in->clt);
    882   strcpy (new->cti, sh_unix_time(0));
     880  sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
     881  sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
     882  sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
    883883  new->next = cmdlist;
    884884  cmdlist   = new;
     
    896896      if (0 == sl_strcmp(new->clt, client_name))
    897897        {
    898           strcpy (new->cmd, in->cmd);
    899           strcpy (new->clt, in->clt);
    900           strcpy (new->cti, sh_unix_time(0));
     898          sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
     899          sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
     900          sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
    901901          return;
    902902        }
     
    905905
    906906  new = SH_ALLOC(sizeof(struct socket_cmd));
    907   strcpy (new->cmd, in->cmd);
    908   strcpy (new->clt, in->clt);
    909   strcpy (new->cti, sh_unix_time(0));
     907  sl_strlcpy (new->cmd, in->cmd, sizeof(new->cmd));
     908  sl_strlcpy (new->clt, in->clt, sizeof(new->clt));
     909  sl_strlcpy (new->cti, sh_unix_time(0), sizeof(new->cti));
    910910  new->next = runlist;
    911911  runlist   = new;
  • trunk/src/sh_srp.c

    r1 r22  
    121121        }
    122122      siz_str_internal = size;
    123       strcpy (get_str_internal, str);                   /* known to fit  */
     123      sl_strlcpy (get_str_internal, str, siz_str_internal);
    124124      for (i = 0; i < (size-1); ++i)
    125125        if (get_str_internal[i] >= 'a' && get_str_internal[i] <= 'f' )
  • trunk/src/sh_static.c

    r1 r22  
    5959#endif
    6060
     61extern  int sl_strlcpy(char * dst, /*@null@*/const char * src, size_t siz);
     62extern  int sl_strlcat(char * dst, /*@null@*/const char * src, size_t siz);
    6163
    6264
     
    884886
    885887#ifdef DEBUG
     888/* flawfinder: ignore *//* definition of debug macro */
    886889#define DPRINTF(X,args...) fprintf(stderr, X, ##args)
    887890#else
     
    11941197                        goto fail;
    11951198
    1196                 strncpy(lookup,name,MAXDNAME);
     1199                sl_strlcpy(lookup,name,MAXDNAME);
    11971200                BIGLOCK;
    11981201                if (variant < __searchdomains && strchr(lookup, '.') == NULL)
    11991202                {
    1200                     strncat(lookup,".", MAXDNAME);
    1201                     strncat(lookup,__searchdomain[variant], MAXDNAME);
     1203                    sl_strlcat(lookup,".", MAXDNAME);
     1204                    sl_strlcat(lookup,__searchdomain[variant], MAXDNAME);
    12021205                }
    12031206                BIGUNLOCK;
  • trunk/src/sh_suidchk.c

    r19 r22  
    415415  long            sl_status = SL_ENONE;
    416416  struct stat     fileInfo;
     417  struct stat     fileInfo_F;
     418  int             file_d;
    417419
    418420  file_type       theFile;
    419421  char            fileHash[2*(KEY_LEN + 1)];
     422
     423  mode_t          umask_old;
     424  int             cperm_status;
    420425
    421426  SL_ENTER(_("sh_suidchk_check_internal"));
     
    666671                                    break;
    667672                                  case SH_Q_CHANGEPERM:
     673                                    cperm_status = 0;
     674                                    file_d = -1;
    668675                                    if (retry_lstat(FIL__, __LINE__, tmpcat, &fileInfo) == -1)
    669676                                      {
     
    677684                                                         tmp );
    678685                                        SH_FREE(msg);
     686                                        cperm_status = -1;
    679687                                      }
    680                                     else
     688
     689                                    if (cperm_status == 0)
    681690                                      {
    682691                                        if (0 != (caperr = sl_get_cap_qdel()))
     
    686695                                                            sh_error_message (caperr),
    687696                                                            _("sl_get_cap_qdel"));
     697                                            cperm_status = -1;
    688698                                          }
    689 
    690                                         if ((fileInfo.st_mode & S_ISUID) > 0)
    691                                           fileInfo.st_mode -= S_ISUID;
    692                                         if ((fileInfo.st_mode & S_ISGID) > 0)
    693                                           fileInfo.st_mode -= S_ISGID;
    694                                         if (chmod(tmpcat, fileInfo.st_mode) == -1)
     699                                      }
     700
     701                                    if (cperm_status == 0)
     702                                      {
     703                                        file_d = aud_open (FIL__, __LINE__, SL_YESPRIV,
     704                                                           tmpcat, O_RDONLY, 0);
     705                                        if (-1 == file_d)
     706                                          {
     707                                            status = errno;
     708                                            msg = SH_ALLOC(SH_BUFSIZE);
     709                                            (void) sl_snprintf(msg, SH_BUFSIZE, _("I/O error.  errno = %ld"), status);
     710                                            sh_error_handle (ShSuidchkSeverity,
     711                                                             FIL__, __LINE__,
     712                                                             status,
     713                                                             MSG_SUID_QREPORT, msg,
     714                                                             tmp );
     715                                            SH_FREE(msg);
     716                                            cperm_status = -1;
     717                                          }
     718                                      }
     719
     720                                    if (cperm_status == 0)
     721                                      {
     722                                        if (retry_fstat(FIL__, __LINE__, file_d, &fileInfo_F) == -1)
     723                                          {
     724                                            status = errno;
     725                                            msg = SH_ALLOC(SH_BUFSIZE);
     726                                            (void) sl_snprintf(msg, SH_BUFSIZE,
     727                                                               _("I/O error.  errno = %ld"), status);
     728                                            sh_error_handle (ShSuidchkSeverity,
     729                                                             FIL__, __LINE__,
     730                                                             status,
     731                                                             MSG_SUID_QREPORT, msg,
     732                                                             tmp );
     733                                            SH_FREE(msg);
     734                                            cperm_status = -1;
     735                                          }
     736                                      }
     737
     738                                    if (cperm_status == 0)
     739                                      {
     740                                        if (fileInfo_F.st_ino  != fileInfo.st_ino ||
     741                                            fileInfo_F.st_dev  != fileInfo.st_dev ||
     742                                            fileInfo_F.st_mode != fileInfo.st_mode)
     743                                          {
     744                                            status = errno;
     745                                            msg = SH_ALLOC(SH_BUFSIZE);
     746                                            (void) sl_snprintf(msg, SH_BUFSIZE,
     747                                                               _("Race detected.  errno = %ld"), status);
     748                                            sh_error_handle (ShSuidchkSeverity,
     749                                                             FIL__, __LINE__,
     750                                                             status,
     751                                                             MSG_SUID_QREPORT, msg,
     752                                                             tmp );
     753                                            SH_FREE(msg);
     754                                            cperm_status = -1;
     755                                          }
     756                                      }
     757
     758                                    if ((fileInfo.st_mode & S_ISUID) > 0)
     759                                      fileInfo.st_mode -= S_ISUID;
     760                                    if ((fileInfo.st_mode & S_ISGID) > 0)
     761                                      fileInfo.st_mode -= S_ISGID;
     762
     763                                    if (cperm_status == 0)
     764                                      {
     765                                        if (fchmod(file_d, fileInfo.st_mode) == -1)
    695766                                          {
    696767                                            status = errno;
     
    713784                                                             tmp );
    714785                                          }
    715                                         if (0 != (caperr = sl_drop_cap_qdel()))
     786                                      }
     787
     788                                    if (0 != (caperr = sl_drop_cap_qdel()))
     789                                      {
     790                                        sh_error_handle((-1), FIL__, __LINE__,
     791                                                        caperr, MSG_E_SUBGEN,
     792                                                        sh_error_message (caperr),
     793                                                        _("sl_drop_cap_qdel"));
     794                                      }
     795
     796                                    if (file_d != -1)
     797                                      {
     798                                        do {
     799                                          status = close (file_d);
     800                                        } while (status == -1 && errno == EINTR);
     801
     802                                        if (-1 == status)
    716803                                          {
    717                                             sh_error_handle((-1), FIL__, __LINE__,
    718                                                             caperr, MSG_E_SUBGEN,
    719                                                             sh_error_message (caperr),
    720                                                             _("sl_drop_cap_qdel"));
     804                                            status = errno;
     805                                            msg = SH_ALLOC(SH_BUFSIZE);
     806                                            (void) sl_snprintf(msg, SH_BUFSIZE,
     807                                                               _("I/O error.  errno = %ld"), status);
     808                                            sh_error_handle (ShSuidchkSeverity,
     809                                                             FIL__, __LINE__,
     810                                                             status,
     811                                                             MSG_SUID_QREPORT, msg,
     812                                                             tmp );
     813                                            SH_FREE(msg);
     814                                            cperm_status = -1;
    721815                                          }
    722816                                      }
     
    725819                                    dir = SH_ALLOC(PATH_MAX+1);
    726820                                    (void) sl_strlcpy (dir, DEFAULT_QDIR, PATH_MAX+1);
    727                                     if (access (dir, F_OK) != 0)
     821                                    if (retry_stat (FIL__, __LINE__, dir, &fileInfo) != 0)
    728822                                      {
    729823                                        status = errno;
    730824                                        msg = SH_ALLOC(SH_BUFSIZE);
    731                                         (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem quarantining file.  File NOT quarantined.  errno = %ld (access)"), status);
     825                                        (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem quarantining file.  File NOT quarantined.  errno = %ld (stat)"), status);
    732826                                        sh_error_handle (ShSuidchkSeverity,
    733827                                                         FIL__, __LINE__,
     
    815909                                                                   DEFAULT_QDIR,
    816910                                                                   basename(theFile.fullpath));
     911                                                /*
     912                                                 * avoid chmod by setting umask
     913                                                 */
     914                                                umask_old = umask (0077);
    817915                                                filePtr = fopen (filetmp, "w+");
    818916                                                /*@-usedef@*/
     
    828926                                                  }
    829927                                                /*@+usedef@*/
     928                                                umask (umask_old);
    830929                                       
    831930                                                sh_error_handle (ShSuidchkSeverity,
     
    834933                                                                 _("Quarantine method applied"),
    835934                                                                 tmp );
    836                                                 if (chmod(filetmp, S_IRUSR | S_IWUSR) == -1)
    837                                                   {
    838                                                     status = errno;
    839                                                     msg = SH_ALLOC(SH_BUFSIZE);
    840                                                     (void) sl_snprintf(msg, SH_BUFSIZE, _("Problem setting permissions on quarantined file.  errno = %ld"), status);
    841                                                     sh_error_handle (ShSuidchkSeverity,
    842                                                                      FIL__,__LINE__,
    843                                                                      status, MSG_SUID_QREPORT,
    844                                                                      msg, tmp );
    845                                                     SH_FREE(msg);
    846                                                   }
    847935                                              }
    848936                                            SH_FREE(filetmp);
     
    9761064  FileLimTotal      = 0;
    9771065
     1066#ifdef SH_SUIDTESTDIR
     1067  status = sh_suidchk_check_internal (SH_SUIDTESTDIR);
     1068#else
    9781069  status = sh_suidchk_check_internal ("/");
     1070#endif
    9791071
    9801072  sh_error_handle ((-1), FIL__, __LINE__, EINVAL, MSG_SUID_SUMMARY,
     
    11691261  long val;
    11701262  int  ret = 0;
     1263  struct stat buf;
    11711264
    11721265  SL_ENTER(_("sh_suidchk_set_qmethod"));
     
    11901283          break;
    11911284        case SH_Q_MOVE:
    1192           if (access (DEFAULT_QDIR, F_OK) != 0)
     1285          if (retry_stat (FIL__, __LINE__, DEFAULT_QDIR, &buf) != 0)
    11931286            {
    11941287              if (mkdir (DEFAULT_QDIR, 0750) == -1)
  • trunk/src/sh_tiger0.c

    r20 r22  
    13921392}
    13931393
    1394 int sh_tiger_hashtype (char * c)
     1394int sh_tiger_hashtype (const char * c)
    13951395{
    13961396  SL_ENTER( _("sh_tiger_hashtype"));
     
    14601460  if (res != NULL)
    14611461    {
    1462       /*@-bufferoverflowhigh -formatconst@*/
    14631462#if defined(TIGER_64_BIT)
    1464       sprintf(out,                                   /* known to fit  */
    1465               MYFORMAT,
    1466               (sh_word32)(res[0]>>32),
    1467               (sh_word32)(res[0]),
    1468               (sh_word32)(res[1]>>32),
    1469               (sh_word32)(res[1]),
    1470               (sh_word32)(res[2]>>32),
    1471               (sh_word32)(res[2]) );
     1463      sl_snprintf(out,
     1464                  sizeof(out),
     1465                  MYFORMAT,
     1466                  (sh_word32)(res[0]>>32),
     1467                  (sh_word32)(res[0]),
     1468                  (sh_word32)(res[1]>>32),
     1469                  (sh_word32)(res[1]),
     1470                  (sh_word32)(res[2]>>32),
     1471                  (sh_word32)(res[2]) );
    14721472#else
    1473       sprintf(out,                                   /* known to fit  */
    1474               MYFORMAT,
    1475               (sh_word32)(res[1]),
    1476               (sh_word32)(res[0]),
    1477               (sh_word32)(res[3]),
    1478               (sh_word32)(res[2]),
    1479               (sh_word32)(res[5]),
    1480               (sh_word32)(res[4]) );
    1481 #endif
    1482       /*@+bufferoverflowhigh@*/
    1483       out[KEY_LEN] = '\0';
     1473      sl_snprintf(out,
     1474                  sizeof(out),
     1475                  MYFORMAT,
     1476                  (sh_word32)(res[1]),
     1477                  (sh_word32)(res[0]),
     1478                  (sh_word32)(res[3]),
     1479                  (sh_word32)(res[2]),
     1480                  (sh_word32)(res[5]),
     1481                  (sh_word32)(res[4]) );
     1482#endif
     1483      out[sizeof(out)-1] = '\0';
    14841484      SL_RETURN( out, _("sh_tiger_hash_internal"));
    14851485
     
    15071507  if (res != NULL)
    15081508    {
    1509       /*@-bufferoverflowhigh -formatconst@*/
    15101509#if defined(TIGER_64_BIT)
    1511       sprintf(outhash,                               /* known to fit  */
    1512               GPGFORMAT,
    1513               (sh_word32)(res[0]>>32),
    1514               (sh_word32)(res[0]),
    1515               (sh_word32)(res[1]>>32),
    1516               (sh_word32)(res[1]),
    1517               (sh_word32)(res[2]>>32),
    1518               (sh_word32)(res[2]) );
     1510      sl_snprintf(outhash,
     1511                  sizeof(outhash),
     1512                  GPGFORMAT,
     1513                  (sh_word32)(res[0]>>32),
     1514                  (sh_word32)(res[0]),
     1515                  (sh_word32)(res[1]>>32),
     1516                  (sh_word32)(res[1]),
     1517                  (sh_word32)(res[2]>>32),
     1518                  (sh_word32)(res[2]) );
    15191519#else
    1520       sprintf(outhash,                               /* known to fit  */
    1521               GPGFORMAT,
    1522               (sh_word32)(res[1]),
    1523               (sh_word32)(res[0]),
    1524               (sh_word32)(res[3]),
    1525               (sh_word32)(res[2]),
    1526               (sh_word32)(res[5]),
    1527               (sh_word32)(res[4]) );
    1528 #endif
    1529       /*@+bufferoverflowhigh@*/
    1530       outhash[48 + 6] = '\0';
     1520      sl_snprintf(outhash,
     1521                  sizeof(outhash),
     1522                  GPGFORMAT,
     1523                  (sh_word32)(res[1]),
     1524                  (sh_word32)(res[0]),
     1525                  (sh_word32)(res[3]),
     1526                  (sh_word32)(res[2]),
     1527                  (sh_word32)(res[5]),
     1528                  (sh_word32)(res[4]) );
     1529#endif
     1530      outhash[sizeof(outhash)-1] = '\0';
    15311531    }
    15321532  else
    15331533    {
    1534       /*@-bufferoverflowhigh@*/
    1535       sprintf(outhash,                               /* known to fit  */
    1536               _("00000000 00000000 00000000  00000000 00000000 00000000"));
    1537       /*@+bufferoverflowhigh@*/
     1534      sl_strlcpy(outhash,
     1535                 _("00000000 00000000 00000000  00000000 00000000 00000000"),
     1536                 sizeof(outhash));
    15381537    }
    15391538
  • trunk/src/sh_tools.c

    r18 r22  
    441441int DoReverseLookup = S_TRUE;
    442442
    443 int set_reverse_lookup (char * c)
     443int set_reverse_lookup (const char * c)
    444444{
    445445  return sh_util_flagval(c, &DoReverseLookup);
     
    462462
    463463  int    retval;
     464  size_t len;
    464465
    465466  sin_cache * check_cache = conn_cache;
     
    535536                  else
    536537                    {
    537                       host_name = SH_ALLOC(sl_strlen(host_entry->h_name) + 1);
    538                       if (sl_strlen(host_entry->h_name) > 0)
    539                         strcpy(host_name,                /* known to fit  */
    540                                host_entry->h_name);
     538                      len = sl_strlen(host_entry->h_name) + 1;
     539                      host_name = SH_ALLOC(len);
     540                      if (len > 1)
     541                        sl_strlcpy(host_name, host_entry->h_name, len);
    541542                      else
    542543                        host_name[0] = '\0';
     
    714715   */
    715716  new_act.sa_handler = SIG_IGN;
     717  sigemptyset( &new_act.sa_mask );         /* set an empty mask       */
     718  new_act.sa_flags = 0;                    /* init sa_flags           */
    716719  sigaction (SIGPIPE, &new_act, &old_act);
    717720 
  • trunk/src/sh_unix.c

    r20 r22  
    307307    *p = '0' + (u % 10);
    308308    u /= 10;
    309   } while (u);
    310   if (iisneg == 1) {
     309  } while (u && (p != str));
     310  if ((iisneg == 1) && (p != str)) {
    311311    --p;
    312312    *p = '-';
     
    323323extern int OnlyStderr;
    324324
    325 int safe_logger (int signal, int method, pid_t thepid)
     325int safe_logger (int signal, int method, char * details)
    326326{
    327327  int i = 0;
     
    331331  char  str[128];
    332332  char  * p;
    333 
     333 
    334334  char l0[64], l1[64], l2[64], l3[64];
    335335  char a0[32], a1[32], a2[32];
    336336  char e0[128];
    337337  char msg[128];
    338 
     338 
    339339  char * locations[] = { NULL, NULL, NULL, NULL, NULL };
    340340  char * envp[]      = { NULL, NULL };
    341341  char * argp[]      = { NULL, NULL, NULL, NULL, NULL };
    342 
     342 
     343  pid_t  thepid = getpid();
     344 
    343345  if ((sh.flag.isdaemon == S_FALSE) || (OnlyStderr == S_TRUE))
    344346    method = 1;
    345 
     347 
    346348  /* seems that solaris cc needs this way of initializing ...
    347349   */
     
    350352  locations[2] = l2;
    351353  locations[3] = l3;
    352 
     354 
    353355  envp[0] = e0;
    354 
     356 
    355357  argp[0] = a0;
    356358  argp[1] = a1;
    357359  argp[2] = a2;
    358 
    359   strcpy (l0, _("/usr/bin/logger"));                   /* known to fit  */
    360   strcpy (l1, _("/usr/sbin/logger"));                  /* known to fit  */
    361   strcpy (l2, _("/usr/ucb/logger"));                   /* known to fit  */
    362   strcpy (l3, _("/bin/logger"));                       /* known to fit  */
    363 
    364   strcpy (a0, _("logger"));                            /* known to fit  */
    365   strcpy (a1, _("-p"));                                /* known to fit  */
    366   strcpy (a2, _("daemon.alert"));                      /* known to fit  */
    367 
    368   strcpy (e0,                                          /* known to fit  */
    369           _("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin"));
    370 
     360 
    371361  sl_strlcpy(msg, _("samhain["), 128);
    372362  p = safe_itoa((int) thepid, str, 128);
     
    375365  if (signal == 0)
    376366    {
    377       sl_strlcat(msg, _("]: out of memory"), 128);
     367      if (details == NULL) {
     368        sl_strlcat(msg, _("]: out of memory"), 128);
     369      } else {
     370        sl_strlcat(msg, _("]: "), 128);
     371        sl_strlcat(msg, details, 128);
     372      }
    378373    }
    379374  else
     
    393388    return 0;
    394389  }
     390
     391  sl_strlcpy (l0, _("/usr/bin/logger"), 64);
     392  sl_strlcpy (l1, _("/usr/sbin/logger"), 64);
     393  sl_strlcpy (l2, _("/usr/ucb/logger"), 64);
     394  sl_strlcpy (l3, _("/bin/logger"), 64);
     395
     396  sl_strlcpy (a0, _("logger"), 32);
     397  sl_strlcpy (a1, _("-p"), 32);
     398  sl_strlcpy (a2, _("daemon.alert"), 32);
     399
     400  sl_strlcpy (e0,
     401              _("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin"),
     402              128);
     403
    395404  while (locations[i] != NULL) {
    396405    status = stat(locations[i], &buf);
     
    414423}
    415424
     425int safe_fatal (int signal, int method, char * details,
     426                char * file, int line)
     427{
     428  char msg[128];
     429  char str[128];
     430  char * p;
     431  p = safe_itoa((int) line, str, 128);
     432  sl_strlcpy(msg, _("FATAL: "), 128);
     433  sl_strlcat(msg, file, 128);
     434  sl_strlcat(msg, ": ", 128);
     435  if (p && (*p)) {
     436    sl_strlcat(msg, p   , 128);
     437    sl_strlcat(msg, ": ", 128);
     438  }
     439  sl_strlcat(msg, details, 128);
     440  safe_logger (signal, method, msg);
     441  _exit(EXIT_FAILURE);
     442}
    416443
    417444extern char sh_sig_msg[64];
     
    451478        {
    452479          chdir ("/");
    453           safe_logger (mysignal, 0, getpid());
     480          safe_logger (mysignal, 0, NULL);
    454481        }
    455482      _exit(mysignal);
     
    504531    memset (skey, '\0', sizeof(sh_key_t));
    505532  if (immediate_exit_fast < 2)
    506     safe_logger (mysignal, 0, getpid());
     533    safe_logger (mysignal, 0, NULL);
    507534  _exit(mysignal);
    508535#else
     
    518545      close_ipc ();
    519546#endif
    520       safe_logger (mysignal, 0, getpid());
     547      safe_logger (mysignal, 0, NULL);
    521548      chdir ("/");
    522549      raise(SIGFPE);
     
    819846/* checksum the own binary
    820847 */
    821 int sh_unix_self_hash (char * c)
     848int sh_unix_self_hash (const char * c)
    822849{
    823850  char message[512];
     
    891918
    892919/* added    Tue Feb 22 10:36:44 NFT 2000 Rainer Wichmann            */
    893 static int tf_add_trusted_user_int(char * c)
     920static int tf_add_trusted_user_int(const char * c)
    894921{
    895922  register struct passwd *          w;
     
    919946}
    920947
    921 int tf_add_trusted_user(char * c)
     948int tf_add_trusted_user(const char * c)
    922949{
    923950  int    i;
     
    12291256  char ** env1;
    12301257  int   envlen = 0;
     1258  size_t len;
    12311259
    12321260  SL_ENTER(_("sh_unix_copyenv"));
     
    12481276  envlen = 0;
    12491277
    1250   while (env0 != NULL && env0[envlen] != NULL) {
    1251     env1[envlen] = malloc (strlen(env0[envlen]) + 1); /* only once */
     1278  while (env0 != NULL && env0[envlen] != NULL) {
     1279    len = strlen(env0[envlen]) + 1;
     1280    env1[envlen] = malloc (len); /* only once */
    12521281    if (env1[envlen] == NULL)
    12531282      {
     
    12551284        SL_RET0(_("sh_unix_copyenv"));
    12561285      }
    1257     strcpy(env1[envlen], env0[envlen]);                /* known to fit  */
     1286    sl_strlcpy(env1[envlen], env0[envlen], len);
    12581287    ++envlen;
    12591288  }
     
    14351464
    14361465  (void) uname (&buf);
    1437 
     1466  /* flawfinder: ignore */ /* ff bug, ff sees system() */
    14381467  sl_strlcpy (sh.host.system,  buf.sysname, SH_MINIBUF);
    14391468  sl_strlcpy (sh.host.release, buf.release, SH_MINIBUF);
     
    16391668          aud_exit(FIL__, __LINE__, EXIT_FAILURE);
    16401669        }
     1670      /* flawfinder: ignore */
    16411671      return (chroot(chroot_dir));
    16421672    }
     
    19231953}
    19241954
    1925 int sh_unix_settimeserver (char * address)
     1955int sh_unix_settimeserver (const char * address)
    19261956{
    19271957
     
    20962126/* whether to use localtime for file timesatams in logs
    20972127 */
    2098 int sh_unix_uselocaltime (char * c)
     2128int sh_unix_uselocaltime (const char * c)
    20992129{
    21002130  int i;
     
    27322762}
    27332763
    2734 int sh_unix_set_io_limit (char * c)
     2764int sh_unix_set_io_limit (const char * c)
    27352765{
    27362766  long val;
     
    27722802  if (tmpFile.size < fbuf->st_size)
    27732803    {
    2774       strcpy(fileHash,                         /* known to fit */
    2775              sh_tiger_generic_hash (filename, TIGER_FD, tmpFile.size,
    2776                                     alert_timeout));
     2804      sl_strlcpy(fileHash,
     2805                sh_tiger_generic_hash (filename, TIGER_FD, tmpFile.size,
     2806                                       alert_timeout),
     2807                KEY_LEN+1);
    27772808
    27782809      /* return */
     
    27812812
    27822813 out:
    2783   strcpy(fileHash,                              /* known to fit */
    2784          _("000000000000000000000000000000000000000000000000"));
     2814  sl_strlcpy(fileHash,
     2815             _("000000000000000000000000000000000000000000000000"),
     2816             KEY_LEN+1);
    27852817  SL_RETURN( -1, _("sh_unix_checksum_size"));
    27862818}
     
    29032935    {
    29042936      if (fileHash != NULL)
    2905         strcpy(fileHash,                              /* known to fit */
    2906                _("000000000000000000000000000000000000000000000000"));
     2937        sl_strlcpy(fileHash,
     2938                   _("000000000000000000000000000000000000000000000000"),
     2939                   KEY_LEN+1);
    29072940    }
    29082941 
     
    29202953          if ((theFile->check_mask & MODI_CHK) == 0)
    29212954            {
    2922               strcpy(fileHash,                         /* known to fit */
    2923                      _("000000000000000000000000000000000000000000000000"));
     2955              sl_strlcpy(fileHash,
     2956                         _("000000000000000000000000000000000000000000000000"),
     2957                         KEY_LEN+1);
    29242958            }
    29252959          else if ((theFile->check_mask & MODI_PREL) != 0 &&
     
    29292963              if (0 != sh_prelink_run (theFile->fullpath,
    29302964                                       fileHash, alert_timeout))
    2931                 strcpy(fileHash,                       /* known to fit */
    2932                        _("000000000000000000000000000000000000000000000000"));
     2965                sl_strlcpy(fileHash,
     2966                           _("000000000000000000000000000000000000000000000000"),
     2967                           KEY_LEN+1);
    29332968            }
    29342969          else
    29352970            {
    29362971              tiger_fd = rval_open;
    2937               strcpy(fileHash,                         /* known to fit */
    2938                      sh_tiger_generic_hash (theFile->fullpath, TIGER_FD, 0,
    2939                                             alert_timeout));
     2972              sl_strlcpy(fileHash,
     2973                         sh_tiger_generic_hash (theFile->fullpath,
     2974                                                TIGER_FD, 0,
     2975                                                alert_timeout),
     2976                         KEY_LEN+1);
    29402977              if ((theFile->check_mask & MODI_SGROW) != 0)
    29412978                {
     
    29602997          if ((theFile->check_mask & MODI_CHK) == 0)
    29612998            {
    2962               strcpy(fileHash,                         /* known to fit */
    2963                      _("000000000000000000000000000000000000000000000000"));
     2999              sl_strlcpy(fileHash,
     3000                         _("000000000000000000000000000000000000000000000000"),
     3001                         KEY_LEN+1);
    29643002            }
    29653003          else if (policy == SH_LEVEL_PRELINK &&
     
    29693007              if (0 != sh_prelink_run (theFile->fullpath,
    29703008                                       fileHash, alert_timeout))
    2971                 strcpy(fileHash,                       /* known to fit */
    2972                        _("000000000000000000000000000000000000000000000000"));
     3009                sl_strlcpy(fileHash,
     3010                           _("000000000000000000000000000000000000000000000000"),
     3011                           KEY_LEN+1);
    29733012            }
    29743013          else
     
    31453184      linknamebuf = SH_ALLOC(PATH_MAX);
    31463185
     3186      /* flawfinder: ignore */
    31473187      linksize    = readlink (theFile->fullpath, linknamebuf, PATH_MAX-1);
    31483188
     
    31603200          SH_FREE(tmp2);
    31613201          SH_FREE(linknamebuf);
     3202          theFile->linkpath[0] = '-';
     3203          theFile->linkpath[1] = '\0';
    31623204          SL_RETURN((-1),_("sh_unix_getinfo"));
    31633205        }
  • trunk/src/sh_utils.c

    r20 r22  
    189189}
    190190
    191 int sh_util_hidesetup(char * c)
     191int sh_util_hidesetup(const char * c)
    192192{
    193193  int i;
     
    646646static int sigtype = TYPE_HMAC;
    647647
    648 int sh_util_sigtype (char * c)
     648int sh_util_sigtype (const char * c)
    649649{
    650650  SL_ENTER(_("sh_util_sigtype"));
     
    957957  char * key;
    958958  char * path;
    959   char * outpath;
     959  char * outpath = NULL;
    960960  unsigned char * image = NULL;
    961961  long s = 0;
     
    963963  long ii, k = 0;
    964964  UINT32    * h1;
    965   char * new;
     965  char * new = NULL;
    966966
    967967  if (0 != sl_is_suid())
     
    999999      fprintf(stderr,
    10001000              _("ERROR: no path to executable given\n Argument must be 'key@path'\n"));
     1001      free(new);
    10011002      _exit (EXIT_FAILURE);
    10021003      /*@notreached@*/
     
    10051006  else
    10061007    path = &new[j];
     1008
     1009  len = strlen(path) + 1 + 4;
    10071010  /*@-usedef@*/
    1008   if (NULL == (outpath = malloc(strlen(path) + 1 + 4)))
     1011  if (NULL == (outpath = malloc(len)))
    10091012    goto bail_mem;
    10101013  /*@-usedef@*/
    1011   /*@-bufferoverflowhigh@*/
    1012   sprintf (outpath, _("%s.out"), path);               /* known to fit  */
    1013   /*@+bufferoverflowhigh@*/
     1014  sl_snprintf (outpath, len, _("%s.out"), path);
    10141015
    10151016  fp = sl_open_read(path, SL_NOPRIV);
     
    10181019      fprintf(stderr,
    10191020              _("ERROR: cannot open %s for read (errnum = %ld)\n"), path, fp);
     1021      free(new); free (outpath);
    10201022      _exit (EXIT_FAILURE);
    10211023      /*@notreached@*/
     
    10281030      fprintf(stderr,
    10291031              _("ERROR: cannot open %s (errnum = %ld)\n"), outpath, fout);
     1032      free(new); free (outpath);
    10301033      _exit (EXIT_FAILURE);
    10311034      /*@notreached@*/
     
    10681071          (void) sl_close (fout);
    10691072          printf(_("new file %s written\n"), outpath);
     1073          free(new); free (outpath); free(image);
    10701074          _exit (EXIT_SUCCESS);
    10711075          /*@notreached@*/
     
    10761080  fprintf(stderr,
    10771081          _("ERROR: old key not found\n"));
     1082  free(new); free (outpath); free(image);
    10781083  _exit (EXIT_FAILURE);
    10791084  /*@notreached@*/
     
    10841089  fprintf(stderr,
    10851090          _("ERROR: out of memory\n"));
     1091  if (new) free(new);
     1092  if (outpath) free (outpath);
     1093  if (image) free (image);
    10861094  _exit (EXIT_FAILURE);
    10871095  /*@notreached@*/
     
    13291337static unsigned char sh_obscure_index[256];
    13301338
    1331 int sh_util_obscure_ok (char * str)
     1339int sh_util_obscure_ok (const char * str)
    13321340{
    13331341  unsigned long   i;
    1334   char * endptr = str;
     1342  char * endptr = NULL;
    13351343
    13361344  SL_ENTER(_("sh_util_obscure_ex"));
     
    13491357      sh_obscure_index[i] = (unsigned char)0;
    13501358    }
     1359
     1360  i = strtoul (str, &endptr, 0);
     1361  if (i > 255)
     1362    {
     1363      SL_RETURN(-1, _("sh_util_obscure_ex"));
     1364    }
     1365  sh_obscure_index[i] = (unsigned char)1;
     1366  if (*endptr == ',')
     1367    ++endptr;
    13511368
    13521369  while (*endptr != '\0')
     
    15621579    } else if (!isgraph ((int) *p)) {    /* not printable    */
    15631580      /*@-bufferoverflowhigh -formatconst@*/
     1581      /* flawfinder: ignore */
    15641582      sprintf(oct, format, '\\',                 /* known to fit  */
    15651583              (unsigned char) *p);
  • trunk/src/slib.c

    r20 r22  
    231231  if (flag == 1)
    232232    {
    233       sprintf        (val, _("\n---------  %10s "), file);
     233      sl_snprintf    (val, 81, _("\n---------  %10s "), file);
    234234      sl_strlcpy     (msg,    val,   80);
    235       sprintf        (val, _(" --- %6d ---------\n"), line);
     235      sl_snprintf    (val, 81, _(" --- %6d ---------\n"), line);
    236236      sl_strlcat     (msg,     val,   80);
    237237      sh_log_console (msg);
     
    578578#if !defined(HOST_IS_I86SOLARIS)
    579579#if !defined (_GNU_SOURCE)
     580/* flawfinder: ignore */
    580581extern int vsnprintf ( char *str, size_t n,
    581582                       const char *format, va_list ap );
     
    777778
    778779#if defined(HAVE_VSNPRINTF) && !defined(HAVE_BROKEN_VSNPRINTF)
    779   len = vsnprintf (str, n, format, vl);
     780  len = vsnprintf (str, n, format, vl);                /* flawfinder: ignore */
    780781  str[n-1] = '\0';
    781782#else
    782   VA_COPY (vl2, vl);                   /* save the argument list           */
     783  VA_COPY (vl2, vl);                     /* save the argument list           */
    783784  total = sl_printf_count (format, vl);
    784   len   = (int) total;
     785  len = (int) total;
    785786  if (total < n)
    786787    {
     788      /* flawfinder: ignore */
    787789      vsprintf (str, format, vl2);       /* program has checked that it fits */
    788790      str[n-1] = '\0';
     
    804806 * ENULL:  src || format == NULL
    805807 * ERANGE: n out of range
    806  * ETRUNC: truncated
     808 * ETRUNC: truncated (unimplemented)
    807809 */
    808810int sl_snprintf(char *str, size_t n,
     
    821823  va_start (vl, format);
    822824#if defined(HAVE_VSNPRINTF) && !defined(HAVE_BROKEN_VSNPRINTF)
     825  /* flawfinder: ignore */
    823826  vsnprintf (str, n, format, vl);
    824827  str[n-1] = '\0';
     
    828831  if (total < n)
    829832    {
     833      /* flawfinder: ignore */
    830834      vsprintf (str, format, vl2);     /* program has checked that it fits */
    831835      str[n-1] = '\0';
     
    15681572SL_TICKET sl_make_ticket (int fd, char * filename)
    15691573{
     1574  size_t    len;
    15701575  SL_TICKET ticket;
    15711576  SL_ENTER(_("sl_make_ticket"));
     
    15871592    }
    15881593
    1589    if ( (ofiles[fd]->path = (char *) malloc( strlen(filename)+1) ) == NULL)
     1594  len = sl_strlen(filename)+1;
     1595
     1596  if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
    15901597    {
    15911598      free(ofiles[fd]);
     
    16051612    }
    16061613
    1607   strcpy (ofiles[fd]->path, filename);                    /* Known to fit  */
     1614  sl_strlcpy (ofiles[fd]->path, filename, len);
    16081615  ofiles[fd]->ticket = ticket;
    16091616  ofiles[fd]->fd     = fd;
     
    16461653  int           fd;
    16471654  int           sflags;
     1655  size_t        len;
    16481656  SL_TICKET     ticket;
    16491657 
     
    18201828    }
    18211829
    1822    if ( (ofiles[fd]->path = (char *) malloc( strlen(filename)+1) ) == NULL)
     1830  len = sl_strlen(filename)+1;
     1831
     1832  if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
    18231833    {
    18241834      free(ofiles[fd]);
     
    18401850    }
    18411851
    1842   strcpy (ofiles[fd]->path, filename);                    /* Known to fit  */
     1852  sl_strlcpy (ofiles[fd]->path, filename, len);
    18431853  ofiles[fd]->ticket = ticket;
    18441854  ofiles[fd]->fd     = fd;
  • trunk/src/yulectl.c

    r1 r22  
    300300  if (0 != good)
    301301    {
    302       fprintf (stderr, _("ERROR: Bounced message != original message.\n"));
     302      fprintf (stderr, _("ERROR: Bounced message != original message (possible reason: superfluous password).\n"));
    303303      return -1;
    304304    }
     
    321321  printf(_("          transfer to the client <client_hostname> when\n"));
    322322  printf(_("          this client connects to deliver a message.\n\n"));
     323  printf(_("          If password is required, it is read from\n"));
     324  printf(_("          $HOME/.yulectl_cred or taken from the environment\n"));
     325  printf(_("          variable YULECTL_PASSWORD (not recommended).\n\n"));
    323326
    324327  printf(_("Commands: RELOAD    <reload configuration>\n"));
     
    337340  FILE * fp;
    338341  struct passwd * pwent;
    339 
     342  char * pw;
     343
     344  pw = getenv(_("YULECTL_PASSWORD"));
     345  if (pw && strlen(pw) < 15)
     346    {
     347      strcpy(password, pw);
     348      strcpy(message2, password);
     349      goto do_msg;
     350    }
    340351 
    341352  pwent = getpwuid(geteuid());
     
    388399      exit(EXIT_FAILURE);
    389400    }
    390   if (strlen(message2) > 15)
     401  if (strlen(message2) > 14)
    391402    {
    392403      fprintf (stderr,
     
    400411    }
    401412  strcpy(password, message2);
     413  fclose(fp);
     414 do_msg:
    402415  strcat(message2, "@");
    403   fclose(fp);
    404416
    405417  strncat(message2, message, SH_MAXMSG - strlen(message2) -1);
Note: See TracChangeset for help on using the changeset viewer.