Changeset 454 for trunk


Ignore:
Timestamp:
Jun 29, 2014, 7:30:04 AM (10 years ago)
Author:
katerina
Message:

Fix for ticket #355 (use calloc instead of malloc).

Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r447 r454  
    1212dnl start
    1313dnl
    14 AM_INIT_AUTOMAKE(samhain, 3.1.1)
     14AM_INIT_AUTOMAKE(samhain, 3.1.2)
    1515AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1616AC_CANONICAL_HOST
  • trunk/docs/Changelog

    r449 r454  
     13.1.2:
     2        * Fixed incorrect memset in sh_checksum.c (sha256)
     3        * Circumvent a gcc compiler bug with inline asm (gcc 4.8)
     4        * Allow multiple exclusions for SUID check
     5        * Use calloc instead of malloc
     6
    173.1.1 (01-0-2014):
    28        * Disable inline asm on Cygwin (issue reported by Erik)
  • trunk/src/bignum.c

    r435 r454  
    6464#define ulong unsigned long
    6565
    66 /*
    67 extern void *malloc(size_t size);
    68 extern void free();
    69 */
    70 
    7166char *last_string    = NULL;
    7267char *big_end_string = NULL;
     
    232227    dgs_alloc += alloclen;
    233228#endif
    234     digit_ptr = (DIGIT *) malloc(alloclen * sizeof(DIGIT));
     229    digit_ptr = calloc(alloclen, sizeof(DIGIT));
    235230    if (digit_ptr == NULL)
    236231    {
     
    625620    big_set_long((long)1, &big_one);
    626621    length_last_string = 10;
    627     if ((last_string = malloc(length_last_string)) == NULL)
     622    if ((last_string = calloc(1,length_last_string)) == NULL)
    628623    {
    629624        big_errno = BIG_MEMERR;
     
    955950        if (last_string != NULL)
    956951          free(last_string);
    957         if ((last_string = malloc(str_length)) == NULL)
     952        if ((last_string = calloc(1,str_length)) == NULL)
    958953        {
    959954            big_errno = BIG_MEMERR;
  • trunk/src/samhain.c

    r433 r454  
    150150int sh_g_thread()
    151151{
    152   struct gt * ptr = malloc(sizeof(struct gt));
     152  struct gt * ptr = calloc(1,sizeof(struct gt));
    153153  if (!ptr)
    154154    return -1;
     
    640640  /* The struct to hold privileged information.
    641641   */
    642   skey = (sh_key_t *) malloc (sizeof(sh_key_t));
     642  skey = calloc(1,sizeof(sh_key_t));
    643643  if (skey != NULL)
    644644    {
     
    862862  SH_MUTEX_LOCK(mutex_readdir);
    863863
    864   pidlist =  malloc(sizeof(pid_t) * 65535);
     864  pidlist =  calloc(1, sizeof(pid_t) * 65535);
    865865  if (!pidlist)
    866866    goto unlock_and_out;
     
    13761376      if (tzlen < 1024)
    13771377        {
    1378           sh.timezone = malloc (tzlen + 1);
     1378          sh.timezone = calloc(1, tzlen + 1);
    13791379          if (sh.timezone != NULL)
    13801380            (void) sl_strlcpy (sh.timezone, tzptr, tzlen + 1);
  • trunk/src/sh_database.c

    r427 r454  
    14841484    {
    14851485      j = strlen(attr_tab[i].attr_o);
    1486       attr_tab[i].attr = malloc (j+1); /* only once */
     1486      attr_tab[i].attr = calloc(1, j+1); /* only once */
    14871487      if (NULL == attr_tab[i].attr)
    14881488        return;
  • trunk/src/sh_entropy.c

    r345 r454  
    548548    {
    549549      len = sl_strlen(sh.timezone) + 4;
    550       envp[0] = malloc (len);     /* free() ok     */
     550      envp[0] = calloc(1, len);     /* free() ok     */
    551551      if (envp[0] != NULL)
    552552        sl_snprintf (envp[0], len, "TZ=%s", sh.timezone);
  • trunk/src/sh_filetype.c

    r310 r454  
    472472
    473473#ifdef  SH_FILE_MAIN
    474   sh_ftype_arr = malloc((nn+1) * sizeof(struct sh_ftype_rec *));
     474  sh_ftype_arr = calloc((nn+1), sizeof(struct sh_ftype_rec *));
    475475#else
    476476  sh_ftype_arr = SH_ALLOC((nn+1) * sizeof(struct sh_ftype_rec *));
     
    480480    {
    481481#ifdef  SH_FILE_MAIN
    482       sh_ftype_arr[i] = malloc(sizeof(struct sh_ftype_rec));
     482      sh_ftype_arr[i] = calloc(1, sizeof(struct sh_ftype_rec));
    483483#else
    484484      sh_ftype_arr[i] = SH_ALLOC(sizeof(struct sh_ftype_rec));
  • trunk/src/sh_gpg.c

    r391 r454  
    422422    {
    423423      len = sl_strlen(sh.effective.home) + 6;
    424       envp[0] = malloc (len); /* free() ok   */
     424      envp[0] = calloc(1, len); /* free() ok   */
    425425      if (envp[0] != NULL)
    426426        sl_snprintf (envp[0], len, _("HOME=%s"), sh.effective.home);
  • trunk/src/sh_html.c

    r415 r454  
    317317          else
    318318            {
    319               entry_orig = malloc(line_size + 1);        /* free() ok     */
     319              entry_orig = calloc(1, line_size + 1);        /* free() ok     */
    320320              if (entry_orig) { entry_orig[0] = '\0'; add_size = line_size; }
    321321            }
  • trunk/src/sh_inotify.c

    r405 r454  
    7272  if ((ptr = pthread_getspecific(inotify_key)) == NULL)
    7373    {
    74       ptr = malloc(sizeof(int));
     74      ptr = calloc(1,sizeof(int));
    7575      if (ptr)
    7676        {
  • trunk/src/sh_mem.c

    r292 r454  
    142142  while (this != NULL)
    143143    {
    144       memlist_t   * merr = (memlist_t *) malloc (sizeof(memlist_t));
     144      memlist_t   * merr = calloc(1,sizeof(memlist_t));
    145145
    146146      memcpy(merr, this, sizeof(memlist_t));
     
    191191      if ( this->address == NULL )
    192192        {
    193           merr = (memlist_t *) malloc (sizeof(memlist_t));
     193          merr = calloc (1,sizeof(memlist_t));
    194194
    195195          memcpy(merr, this, sizeof(memlist_t));
     
    204204          if ( this->address[this->size]        != CHECKBYTE )
    205205            {
    206               merr = (memlist_t *) malloc (sizeof(memlist_t));
     206              merr = calloc(1, sizeof(memlist_t));
    207207             
    208208              memcpy(merr, this, sizeof(memlist_t));
     
    215215          if ( this->real_address[SH_MEMMULT-1] != CHECKBYTE )
    216216            {
    217               merr = (memlist_t *) malloc (sizeof(memlist_t));
     217              merr = calloc(1, sizeof(memlist_t));
    218218             
    219219              memcpy(merr, this, sizeof(memlist_t));
     
    262262  SH_MUTEX_RECURSIVE_LOCK(mutex_mem);
    263263
    264   the_realAddress = malloc(size + 2 * SH_MEMMULT);
     264  the_realAddress = calloc(1,size + 2 * SH_MEMMULT);
    265265 
    266266  if ( the_realAddress  == NULL )
     
    290290  Mem_Max = ( (Mem_Current > Mem_Max) ? Mem_Current : Mem_Max);
    291291
    292   this = (memlist_t *) malloc (sizeof(memlist_t));
     292  this = calloc(1,sizeof(memlist_t));
    293293
    294294  if ( this == NULL)
     
    370370      if ( this->address[this->size]        != CHECKBYTE )
    371371        {
    372           merr = (memlist_t *) malloc (sizeof(memlist_t));
     372          merr = calloc(1, sizeof(memlist_t));
    373373
    374374          memcpy(merr, this, sizeof(memlist_t));
     
    381381      if ( this->real_address[SH_MEMMULT-1] != CHECKBYTE )
    382382        {
    383           merr = (memlist_t *) malloc (sizeof(memlist_t));
     383          merr = calloc(1,sizeof(memlist_t));
    384384
    385385          memcpy(merr, this, sizeof(memlist_t));
     
    454454  SL_ENTER(_("sh_mem_malloc"));
    455455
    456   theAddress = malloc(size);
     456  theAddress = calloc(1,size);
    457457
    458458  if ( theAddress != NULL )
  • trunk/src/sh_schedule.c

    r290 r454  
    335335  len = strlen(ssched)+1;
    336336#ifdef TESTONLY
    337   copy = malloc(len);                 /* testonly code */
     337  copy = calloc(1,len);                 /* testonly code */
    338338#else
    339339  copy = SH_ALLOC(len);
  • trunk/src/sh_srp.c

    r225 r454  
    9696  if (get_str_internal == NULL)
    9797    {
    98       get_str_internal = malloc(512);   /* only once */
     98      get_str_internal = calloc(1,512);   /* only once */
    9999      if (get_str_internal)
    100100        {
  • trunk/src/sh_static.c

    r428 r454  
    469469        struct group group;
    470470
    471         char * buff = malloc(GRP_BUFFER_SIZE_MALLOC);
     471        char * buff = calloc(1,GRP_BUFFER_SIZE_MALLOC);
    472472
    473473        rv = -1;
    474474
    475475        /* We alloc space for 8 gids at a time. */
    476         if (((group_list = (gid_t *) malloc(8*sizeof(gid_t *))) != NULL)
     476        if (((group_list = calloc(8,sizeof(gid_t *))) != NULL)
    477477                && ((grf = fopen(_PATH_GROUP, "r")) != NULL)
    478478                ) {
     
    11771177        struct resolv_question q;
    11781178        int retries = 0;
    1179         unsigned char * packet = malloc(PACKETSZ);
    1180         char *dns, *lookup = malloc(MAXDNAME);
     1179        unsigned char * packet = calloc(1,PACKETSZ);
     1180        char *dns, *lookup = calloc(1,MAXDNAME);
    11811181        int variant = 0;
    11821182        struct sockaddr_in sa;
  • trunk/src/sh_unix.c

    r436 r454  
    14751475
    14761476  /* printf("-> %2d: slots allocated\n", envlen); */
    1477   env1 = malloc (sizeof(char *) * envlen);      /* only once */
     1477  env1 = calloc(1,sizeof(char *) * envlen);      /* only once */
    14781478  if (env1 == NULL)
    14791479    {
     
    14861486  while (env0 != NULL && env0[envlen] != NULL) {
    14871487    len = strlen(env0[envlen]) + 1;
    1488     env1[envlen] = malloc (len); /* only once */
     1488    env1[envlen] = calloc(1,len); /* only once */
    14891489    if (env1[envlen] == NULL)
    14901490      {
     
    19101910    {
    19111911      len = strlen(str) + 1;
    1912       chroot_dir = malloc(strlen(str) + 1);  /* only once */
     1912      chroot_dir = calloc(1,strlen(str) + 1);  /* only once */
    19131913      if (!chroot_dir)
    19141914        {
     
    43494349              sh_error_handle (level, FIL__, __LINE__, stat_return,
    43504350                               MSG_FI_STAT,
    4351                                _("lstat"),
     4351                               _("lstat (link target)"),
    43524352                               sh_error_message (stat_return,errbuf, sizeof(errbuf)),
    43534353                               (long) euid,
     
    55685568  ptr = pthread_getspecific(gSigtrapVariables_key);
    55695569  if (ptr == NULL) {
    5570     ptr = malloc(sizeof(struct sh_sigtrap_variables));
     5570    ptr = calloc(1,sizeof(struct sh_sigtrap_variables));
    55715571    if (ptr == NULL) {
    55725572      return NULL;
  • trunk/src/sh_utils.c

    r444 r454  
    12551255    }
    12561256
    1257   if (NULL == (new = malloc(strlen(new_in) + 1)))
     1257  if (NULL == (new = calloc(1,strlen(new_in) + 1)))
    12581258    goto bail_mem;
    12591259  sl_strncpy(new, new_in, strlen(new_in) + 1);
     
    12821282  len = strlen(path) + 1 + 4;
    12831283  /*@-usedef@*/
    1284   if (NULL == (outpath = malloc(len)))
     1284  if (NULL == (outpath = calloc(1,len)))
    12851285    goto bail_mem;
    12861286  /*@-usedef@*/
     
    13101310
    13111311
    1312   image = malloc (4096);
     1312  image = calloc(1,4096);
    13131313  if (!image)
    13141314    goto bail_mem;
  • trunk/src/slib.c

    r412 r454  
    14931493      char          *  buffer;
    14941494      struct passwd *  tempres;
    1495       buffer = malloc(SH_PWBUF_SIZE);
     1495      buffer = calloc(1,SH_PWBUF_SIZE);
    14961496      SL_REQUIRE (buffer != NULL, _("buffer != NULL"));
    14971497      sh_getpwnam_r(user, &pwd, buffer, SH_PWBUF_SIZE, &tempres);
     
    15421542      char          *  buffer;
    15431543      struct passwd *  tempres;
    1544       buffer = malloc(SH_PWBUF_SIZE);
     1544      buffer = calloc(1,SH_PWBUF_SIZE);
    15451545      SL_REQUIRE (buffer != NULL, _("buffer != NULL"));
    15461546      sh_getpwnam_r(user, &pwd, buffer, SH_PWBUF_SIZE, &tempres);
     
    17561756    }
    17571757
    1758   if ( (ofiles[fd] = (SL_OFILE *) malloc(sizeof(SL_OFILE))) == NULL)
     1758  if ( (ofiles[fd] = calloc(1,sizeof(SL_OFILE))) == NULL)
    17591759    {
    17601760      SL_IRETURN(SL_EMEM, _("sl_make_ticket"));
     
    17631763  len = sl_strlen(filename)+1;
    17641764
    1765   if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
     1765  if ( (ofiles[fd]->path = calloc(1,len) ) == NULL)
    17661766    {
    17671767      free (ofiles[fd]);
     
    20322032    }
    20332033
    2034   if ( (ofiles[fd] = (SL_OFILE *) malloc(sizeof(SL_OFILE))) == NULL)
     2034  if ( (ofiles[fd] = calloc(1,sizeof(SL_OFILE))) == NULL)
    20352035    {
    20362036      sl_close_fd(FIL__, __LINE__, fd);
     
    20402040  len = sl_strlen(filename)+1;
    20412041
    2042   if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
     2042  if ( (ofiles[fd]->path = calloc(1,len) ) == NULL)
    20432043    {
    20442044      free (ofiles[fd]);
  • trunk/src/sstrip.c

    r286 r454  
    178178
    179179    size = ehdr->e_phnum * sizeof **phdrs;
    180     if (!(*phdrs = malloc(size)))
     180    if (!(*phdrs = calloc(1,size)))
    181181        return err("Out of memory!");
    182182
     
    196196
    197197    size = ehdr->e_phnum * sizeof **phdrs;
    198     if (!(*phdrs = malloc(size)))
     198    if (!(*phdrs = calloc(1,size)))
    199199        return err("Out of memory!");
    200200
  • trunk/src/t-test1.c

    r229 r454  
    2727 * allocated bins per thread.
    2828 */
     29/*
     30  t-test[12] <n-total> <n-parallel> <n-allocs> <size-max> <bins>
     31
     32    n-total = total number of threads executed (default 10)
     33    n-parallel = number of threads running in parallel (2)
     34    n-allocs = number of malloc()'s / free()'s per thread (10000)
     35    size-max = max. size requested with malloc() in bytes (10000)
     36    bins = number of bins to maintain
     37*/
     38
    2939#if defined(HAVE_CONFIG_H)
    3040#include "config.h"
     
    5262
    5363#ifdef USE_SYSTEM_MALLOC
    54 #define memalign(a,b)  malloc(b)
     64extern void *memalign(size_t boundary, size_t size);
     65/* #define memalign(a,b)  malloc(b) */
    5566#else
    5667extern void *memalign(size_t boundary, size_t size);
     
    203214/* Allocate a bin with malloc(), realloc() or memalign().  r must be a
    204215   random number >= 1024. */
     216int n_malloc=0, n_memalign=0, n_realloc=0, n_calloc=0;
    205217
    206218static void
     
    219231                m->ptr = (unsigned char *)memalign(sizeof(int) << r, size);
    220232                /* fprintf(stderr, "FIXME memalign %p\n", m->ptr); */
     233                ++n_memalign;
    221234        } else if(r < 20) { /* calloc */
    222235                if(m->size > 0) free(m->ptr);
     
    232245                }
    233246#endif
     247                ++n_calloc;
    234248                /* fprintf(stderr, "FIXME calloc %p\n", m->ptr); */
    235249        } else if(r < 100 && m->size < REALLOC_MAX) { /* realloc */
     
    237251                m->ptr = realloc(m->ptr, size);
    238252                /* fprintf(stderr, "FIXME realloc %p\n", m->ptr); */
     253                ++n_realloc;
    239254        } else { /* plain malloc */
    240255                if(m->size > 0) free(m->ptr);
    241256                m->ptr = (unsigned char *)malloc(size);
    242257                /* fprintf(stderr, "FIXME malloc %p\n", m->ptr); */
     258                ++n_malloc;
    243259        }
    244260        if(!m->ptr) {
     
    540556                if (verbose)
    541557                  if(n_total%N_TOTAL_PRINT == 0)
    542                         printf("n_total = %d\n", n_total);
     558                        printf("n_total = %8d - malloc %12d / memalign %12d / realloc %12d / calloc %12d\n",
     559                                   n_total,
     560                                   n_malloc, n_memalign, n_realloc, n_calloc);
    543561               
    544562        }
     
    578596        printf("ptmalloc_init\n");
    579597#endif
     598
     599        if((argc > 1) && (0 == strcmp(argv[1], "-h") || 0 == strcmp(argv[1], "--help")))
     600          {
     601                printf("%s <n-total> <n-parallel> <n-allocs> <size-max> <bins>\n\n", argv[0]);
     602                printf(" n-total = total number of threads executed (default 10)\n");
     603                printf(" n-parallel = number of threads running in parallel (2)\n");
     604                printf(" n-allocs = number of malloc()'s / free()'s per thread (10000)\n");
     605                printf(" size-max = max. size requested with malloc() in bytes (10000)\n");
     606                printf(" bins = number of bins to maintain\n");
     607                return 0;
     608          }
    580609
    581610        if(argc > 1) n_total_max = atoi(argv[1]);
  • trunk/src/trustfile.c

    r430 r454  
    436436
    437437#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    438   buffer = malloc(SH_GRBUF_SIZE);
     438  buffer = calloc(1,SH_GRBUF_SIZE);
    439439  status = sh_getgrgid_r(grp, &gr, buffer, SH_GRBUF_SIZE, &g);
    440440#else
     
    455455   */
    456456#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    457   pbuffer = malloc(SH_PWBUF_SIZE);
     457  pbuffer = calloc(1,SH_PWBUF_SIZE);
    458458#endif
    459459
     
    549549
    550550#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETGRGID_R)
    551   buffer = malloc(SH_GRBUF_SIZE);
     551  buffer = calloc(1,SH_GRBUF_SIZE);
    552552  status = sh_getgrgid_r(grp, &gr, buffer, SH_GRBUF_SIZE, &g);
    553553#else
     
    580580   */
    581581#if defined(HAVE_PTHREAD) && defined (_POSIX_THREAD_SAFE_FUNCTIONS) && defined(HAVE_GETPWNAM_R)
    582   pbuffer = malloc(SH_PWBUF_SIZE);
     582  pbuffer = calloc(1,SH_PWBUF_SIZE);
    583583#endif
    584584
     
    747747    SL_IRETURN(SL_EBADFILE, _("sl_trustfile"));
    748748
    749   fexp = malloc( MAXFILENAME );
     749  fexp = calloc(1, MAXFILENAME );
    750750  if (!fexp)
    751751    SL_IRETURN(SL_EMEM, _("sl_trustfile"));
     
    863863           * R.W. Tue May 29 22:05:16 CEST 2001
    864864           */
    865           csym = malloc( MAXFILENAME );
     865          csym = calloc(1, MAXFILENAME );
    866866          if (!csym)
    867867            {
     
    886886            }
    887887
    888           full = malloc( MAXFILENAME );
     888          full = calloc(1, MAXFILENAME );
    889889          if (!full)
    890890            {
  • trunk/src/yulectl.c

    r396 r454  
    591591    }
    592592  size = strlen(clientcd) + 1 + strlen(CLIENT) + 6;
    593   sockname = malloc (size);
     593  sockname = calloc(1,size);
    594594  if (!sockname)
    595595    {
Note: See TracChangeset for help on using the changeset viewer.