Changeset 171 for trunk/src


Ignore:
Timestamp:
Jul 8, 2008, 11:16:14 AM (16 years ago)
Author:
katerina
Message:

Include dnmalloc (ticket #108) and fix bugs #106 (EINPROGRESS) and #107 (compressBound).

Location:
trunk/src
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cutest_sh_unix.c

    r30 r171  
    77#include "sh_unix.h"
    88
     9int malloc_count = 0;
     10
     11void Test_dnmalloc (CuTest *tc) {
     12
     13  const int nalloc = 64 /* original dnmalloc 1.0-beta5 fails fo >= 45 */;
     14  int j, i;
     15  int sum;
     16  int i_malloc =  malloc_count;
     17
     18  char * buf;
     19  char * area[256];
     20
     21  /* test reuse of last freed chunk */
     22  buf = malloc(1024);
     23  CuAssertPtrNotNull(tc, buf);
     24  free(buf);
     25  area[0] = malloc(1024);
     26  CuAssertTrue(tc, buf == area[0]);
     27  free(area[0]);
     28
     29  /* test realloc */
     30  buf = malloc(16);
     31  CuAssertPtrNotNull(tc, buf);
     32  strcpy(buf, "testing realloc");
     33  buf = realloc(buf, 32);
     34  strcat(buf, "testing realloc");
     35  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     36
     37  i_malloc = malloc_count;
     38
     39  for (j = 0; j < 64; ++j)
     40    {
     41      buf = malloc((j+1) * 1024);
     42      CuAssertPtrNotNull(tc, buf);
     43#ifndef USE_SYSTEM_MALLOC
     44      CuAssertIntEquals (tc, malloc_count, (i_malloc + 1));
     45#endif
     46      free(buf);
     47#ifndef USE_SYSTEM_MALLOC
     48      CuAssertIntEquals (tc, malloc_count, i_malloc);
     49#endif
     50    }
     51
     52  /* test realloc */
     53  buf = malloc(16);
     54  CuAssertPtrNotNull(tc, buf);
     55  strcpy(buf, "testing realloc");
     56  buf = realloc(buf, 32);
     57  strcat(buf, "testing realloc");
     58  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     59
     60  i_malloc = malloc_count;
     61
     62  for (j = 0; j < 64; ++j)
     63    {
     64      buf = calloc(1, (j+1) * 1024);
     65      CuAssertPtrNotNull(tc, buf);
     66#ifndef USE_SYSTEM_MALLOC
     67      CuAssertIntEquals (tc, malloc_count, (i_malloc + 1));
     68#endif
     69      sum = 0;
     70      for (i = 0; i < ((j+1) * 1024); ++i)
     71        sum += buf[i];
     72      CuAssertIntEquals (tc, 0, sum);
     73      free(buf);
     74#ifndef USE_SYSTEM_MALLOC
     75      CuAssertIntEquals (tc, malloc_count, i_malloc);
     76#endif
     77    }
     78
     79  /* test realloc */
     80  buf = malloc(16);
     81  CuAssertPtrNotNull(tc, buf);
     82  strcpy(buf, "testing realloc");
     83  buf = realloc(buf, 32);
     84  strcat(buf, "testing realloc");
     85  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     86
     87  for (j = 0; j < nalloc; ++j)
     88    {
     89      area[j] = malloc((j+1) * 1024);
     90      CuAssertPtrNotNull(tc, area[j]);
     91#ifndef USE_SYSTEM_MALLOC
     92      // CuAssertIntEquals (tc, malloc_count, (i_malloc + (j+1)));
     93#endif
     94      memset(area[j], (unsigned char) ('a'+1), (j+1) * 1024);
     95    }
     96
     97  i_malloc =  malloc_count;
     98
     99  for (j = 0; j < nalloc; ++j)
     100    {
     101      sum = 0;
     102      for (i = 0; i < ((j+1) * 1024); ++i)
     103        sum +=  area[j][i];
     104      CuAssertIntEquals (tc, sum, ((j+1) * 1024 * ((unsigned char) ('a'+1))));
     105      free(area[j]);
     106#ifndef USE_SYSTEM_MALLOC
     107      CuAssertIntEquals (tc, malloc_count, i_malloc - (j+1));
     108#endif
     109    }
     110
     111  /* test realloc */
     112  buf = malloc(16);
     113  CuAssertPtrNotNull(tc, buf);
     114  strcpy(buf, "testing realloc");
     115  buf = realloc(buf, 32);
     116  strcat(buf, "testing realloc");
     117  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     118
     119
     120  for (j = 0; j < 32; ++j)
     121    {
     122      i_malloc =  malloc_count;
     123      buf = malloc((j+1) * 1024 * 1024);
     124      CuAssertPtrNotNull(tc, buf);
     125      for (i = 0; i < 32; ++i)
     126        {
     127          area[i] = malloc((i+1) * 1024);
     128          CuAssertPtrNotNull(tc, area[i]);
     129        }
     130      free(buf);
     131      for (i = 0; i < 32; ++i)
     132        {
     133          free(area[i]);
     134        }
     135#ifndef USE_SYSTEM_MALLOC
     136      CuAssertIntEquals (tc, malloc_count, i_malloc);
     137#endif
     138    }
     139
     140  /* test realloc */
     141  buf = malloc(16);
     142  CuAssertPtrNotNull(tc, buf);
     143  strcpy(buf, "testing realloc");
     144  buf = realloc(buf, 32);
     145  strcat(buf, "testing realloc");
     146  CuAssertStrEquals(tc, "testing realloctesting realloc", buf);
     147}
     148
     149 
    9150void Test_sh_unix_lookup_page (CuTest *tc) {
    10151
  • trunk/src/make-tests.sh

    r29 r171  
    5757int main(void)
    5858{
     59#if !defined(USE_SYSTEM_MALLOC) && defined(USE_MALLOC_LOCK)
     60    extern int dnmalloc_pthread_init(void);
     61    dnmalloc_pthread_init();
     62#endif
    5963    int retval;
    6064    retval = RunAllTests();
  • trunk/src/samhain.c

    r170 r171  
    169169void sh_g_init(void)
    170170{
     171#if !defined(USE_SYSTEM_MALLOC) && defined(USE_MALLOC_LOCK)
     172  extern int dnmalloc_pthread_init(void);
     173  dnmalloc_pthread_init();
     174#endif
     175
    171176  if (0 != pthread_key_create(&g_key, sh_g_destroy))
    172177    {
     
    21522157#endif
    21532158
     2159#if 0
     2160  {
     2161    char command[128];
     2162    sprintf(command, "/bin/cat /proc/%d/status", (int) getpid());
     2163    system(command); /* flawfinder: ignore *//* debug code */
     2164    malloc_stats();
     2165  }
     2166#endif
     2167
    21542168  aud_exit (FIL__, __LINE__, EXIT_SUCCESS);
    21552169  SL_RETURN(0, _("main"));
  • trunk/src/samhain_setpwd.c

    r170 r171  
    88#include <unistd.h>
    99#include <sys/types.h>
     10#include <signal.h>
    1011#include <sys/wait.h>
    1112#include <sys/stat.h>
     
    7071    }
    7172
    72   while (nbytes) {
     73  do {
    7374    count = read(fd, &buf[where], nbytes);
    7475    if (count == -1 && errno == EINTR)
     
    7677    where  += count;
    7778    nbytes -= count;
    78   } while (count == -1 && errno == EINTR);
     79  } while (nbytes);
    7980
    8081  close(fd);
  • trunk/src/sh_calls.c

    r170 r171  
    183183        val_retry =
    184184          /*@-unrecog@*/connect(sockfd, serv_addr, addrlen)/*@+unrecog@*/;
    185       } while (val_retry < 0 && errno == EINTR);
     185      } while (val_retry < 0 && (errno == EINTR || errno == EINPROGRESS));
    186186    }
    187187
  • trunk/src/sh_entropy.c

    r170 r171  
    147147        struct sockaddr_un addr;
    148148        int addr_len;
     149        int retval;
    149150
    150151#ifdef EGD_SOCKET_NAME
     
    184185            SL_RETURN( -1, _("sh_entropy") );
    185186          }
    186         if( connect( fd, (struct sockaddr*)&addr, addr_len) == -1 )
     187        do {
     188          retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr));
     189        } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS));
     190        if( retval == -1 )
    187191          {
    188192            myerror = errno;
     
    682686        status = -1;
    683687      }
     688#if !defined(USE_UNO)
    684689    else if (WIFSIGNALED(status))
    685690      {
     
    692697        status = -1;
    693698      }
     699#endif
    694700
    695701    source->pipe = NULL;
  • trunk/src/sh_files.c

    r170 r171  
    22542254int sh_files_test_double (zAVLTree * firstList, zAVLTree * secondList)
    22552255{
    2256   int          count;
    22572256  int          retval = 0;
    2258 
    22592257  zAVLCursor   cursor;
    2260 
    22612258  dirstack_t * first;
    22622259
     
    22672264      if (NULL != zAVLSearch(secondList, first->name))
    22682265        {
    2269           ++count;
    22702266          sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_FI_DOUBLE,
    22712267                           first->name);
  • trunk/src/sh_forward.c

    r170 r171  
    26442644                               sizeof(addr_peer.sin_addr)))
    26452645                break;
    2646               ++i;
    26472646            }
    26482647        }
     
    49164915  struct  sigaction  new_act;
    49174916  struct  sigaction  old_act;
     4917
     4918  int setsize_fd;
    49184919 
    49194920  SL_ENTER(_("sh_receive"));
     
    49464947   * The POSIX lower limit on open files seems to be eight.
    49474948   */
    4948   maxconn = get_open_max() - 6;
    4949   maxconn = (((int)FD_SETSIZE) < maxconn) ? FD_SETSIZE : maxconn;
     4949  maxconn    = get_open_max() - 6;
     4950  /* ugly fix for FreeBSD compiler warning; casting FD_SETSIZE in the
     4951   * conditional expression does not suppress the warning... */
     4952  setsize_fd = (int)FD_SETSIZE;
     4953  maxconn = (setsize_fd < maxconn) ? setsize_fd : maxconn;
    49504954
    49514955  if (maxconn < 0 || !sl_ok_muls(maxconn, sizeof(sh_conn_t)))
  • trunk/src/sh_getopt.c

    r170 r171  
    315315static void sh_getopt_print_log_facilities (void)
    316316{
    317   fputs (_("Compiled-in log facilities:"), stdout);
     317  int num = 0;
     318
     319  fputs (_("Compiled-in log facilities:\n"), stdout);
    318320
    319321#ifndef DEFAULT_CONSOLE
    320   printf (_(" console (/dev/console)"));
     322  if (num > 0) fputc ('\n', stdout);
     323  printf (_(" console (/dev/console)")); ++num;
    321324#else
     325  if (num > 0) fputc ('\n', stdout);
    322326  if (0 == strcmp (DEFAULT_CONSOLE, _("NULL")))
    323     printf (_(" console (/dev/console)"));
     327    { printf (_("console (/dev/console)"));  ++num; }
    324328  else
    325     printf (_(" console (%s)"), DEFAULT_CONSOLE);
    326 #endif
    327   fputs  (_(", syslog"), stdout);
    328   printf (_(", logfile (%s)"), DEFAULT_ERRFILE);
     329    { printf (_("console (%s)"), DEFAULT_CONSOLE);  ++num; }
     330#endif
     331  if (num > 0) fputc ('\n', stdout);
     332  fputs  (_(" syslog"), stdout); ++num;
     333  if (num > 0) fputc ('\n', stdout);
     334  printf (_(" logfile (%s)"), DEFAULT_ERRFILE); ++num;
    329335
    330336#if defined(WITH_EXTERNAL)
    331   fputs (_(", external program"), stdout);
     337  if (num > 0) fputc ('\n', stdout);
     338  fputs (_(" external program"), stdout); ++num;
    332339#endif
    333340
    334341#if defined(WITH_MESSAGE_QUEUE)
    335   fputs (_(", message queue"), stdout);
     342  if (num > 0) fputc ('\n', stdout);
     343  fputs (_(" message queue"), stdout); ++num;
    336344#endif
    337345 
    338346#if defined(WITH_DATABASE)
    339   fputs (_(", database"), stdout);
     347  if (num > 0) fputc ('\n', stdout);
     348  fputs (_(" database"), stdout); ++num;
    340349#ifdef WITH_ODBC
    341350  fputs (_(" (odbc)"), stdout);
     
    353362
    354363#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
    355   fputs (_(", server"), stdout);
     364  if (num > 0) fputc ('\n', stdout);
     365  fputs (_(" server"), stdout); ++num;
    356366#endif
    357367
    358368#if defined(SH_WITH_MAIL)
    359   fputs (_(", email"), stdout);
     369  if (num > 0) fputc ('\n', stdout);
     370  fputs (_(" email"), stdout); ++num;
    360371#endif
    361372
    362373#ifdef HAVE_LIBPRELUDE
     374  if (num > 0) fputc ('\n', stdout); ++num;
    363375#ifdef HAVE_LIBPRELUDE_8
    364   fputs (_(", prelude (0.8)"), stdout);
     376  fputs (_(" prelude (0.8)"), stdout);
    365377#else
    366   fputs (_(", prelude (0.9+)"), stdout);
    367 #endif
    368 #endif
    369 
    370   fputc ('\n', stdout);
    371   return;
    372 }
    373 
    374 static void sh_getopt_print_options (void)
    375 {
    376   int num = 0;
    377 
    378 
    379 #if defined(SH_STANDALONE)
    380   if (num > 0) fputc ('\n', stdout);
    381   fputs (_("Standalone executable"), stdout); ++num;
    382 #endif
    383 #if defined(SH_WITH_CLIENT)
    384   if (num > 0) fputc ('\n', stdout);
    385   printf (_("Client executable (port %d)"), SH_DEFAULT_PORT); ++num;
    386 #endif
    387 #if defined(SH_WITH_CLIENT)
    388   if (num > 0) fputc ('\n', stdout);
    389   printf (_("Server executable (port %d, user %s)"),
    390           SH_DEFAULT_PORT, DEFAULT_IDENT);
    391   ++num;
    392 #endif
    393 
    394   fputs (_(", compiled-in options:"), stdout);
    395 
    396 #if defined(HAVE_EGD_RANDOM)
    397   if (num > 0) fputc ('\n', stdout);
    398   printf (_(" use entropy gathering daemon (%s)"), EGD_SOCKET_NAME); ++num;
    399 #endif
    400 #if defined(HAVE_UNIX_RANDOM)
    401   if (num > 0) fputc ('\n', stdout);
    402   fputs (_(" use unix entropy gatherer"), stdout); ++num;
    403 #endif
    404 #if defined(HAVE_URANDOM)
    405   if (num > 0) fputc ('\n', stdout);
    406   printf (_(" use entropy device (%s)"), NAME_OF_DEV_RANDOM); ++num;
    407 #endif
    408 
    409 #ifdef WITH_GPG
    410   if (num > 0) fputc ('\n', stdout);
    411   printf (_(" GnuPG signatures (%s)"), DEFAULT_GPG_PATH); ++num;
    412 #ifdef HAVE_GPG_CHECKSUM
    413   if (num > 0) fputc ('\n', stdout);
    414   printf (_("   -- GnuPG checksum:  %s"), GPG_HASH); ++num;
    415 #endif
    416 #ifdef USE_FINGERPRINT
    417   if (num > 0) fputc ('\n', stdout);
    418   printf (_("   -- Key fingerprint: %s"), SH_GPG_FP); ++num;
    419 #endif
    420 #endif
    421 
    422 #if defined(SL_DEBUG)
    423   if (num > 0) fputc ('\n', stdout);
    424   fputs (_(" debug build (don't use for production)"), stdout); ++num;
    425 #endif
    426 #if defined(SCREW_IT_UP)
    427   if (num > 0) fputc ('\n', stdout);
    428   fputs (_(" anti-debugger"), stdout); ++num;
    429 #endif
    430 #if defined(SH_USE_XML)
    431   if (num > 0) fputc ('\n', stdout);
    432   fputs (_(" xml log format"), stdout); ++num;
    433 #endif
    434 #if defined(HAVE_NTIME)
    435   if (num > 0) fputc ('\n', stdout);
    436   fputs (_(" use time server"), stdout); ++num;
    437 #endif
    438 
    439 #if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
    440 #if defined(HAVE_LIBZ)
    441   if (num > 0) fputc ('\n', stdout);
    442   fputs (_(" optionally store full text for files"), stdout); ++num;
    443 #endif
    444 #if defined(USE_XATTR)
    445   if (num > 0) fputc ('\n', stdout);
    446   fputs (_(" check SELinux attributes"), stdout); ++num;
    447 #endif
    448 #if defined(USE_ACL)
    449   if (num > 0) fputc ('\n', stdout);
    450   fputs (_(" check Posix ACLs"), stdout); ++num;
    451 #endif
    452 #if defined(RELOAD_DATABASE)
    453   if (num > 0) fputc ('\n', stdout);
    454   fputs (_(" fetch database on reload"), stdout); ++num;
    455 #endif
    456 #endif
    457 
    458 #if defined(SH_WITH_SERVER)
    459 
    460 #if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
    461   if (num > 0) fputc ('\n', stdout);
    462   fputs (_(" command socket authentication: use SetSocketPassword"), stdout);
    463   ++num;
    464 #else
    465   if (num > 0) fputc ('\n', stdout);
    466   fputs (_(" command socket authentication: use SetSocketAllowUID"), stdout);
    467   ++num;
    468 #endif
    469 
    470 #if defined(SH_USE_LIBWRAP)
    471   if (num > 0) fputc ('\n', stdout);
    472   fputs (_(" support tcp wrapper"), stdout); ++num;
    473 #endif
    474 #if defined(INET_SYSLOG)
    475   if (num > 0) fputc ('\n', stdout);
    476   fputs (_(" support listening on 514/udp (syslog)"), stdout); ++num;
     378  fputs (_(" prelude (0.9+)"), stdout);
    477379#endif
    478380#endif
     
    484386}
    485387
     388static void sh_getopt_print_options (void)
     389{
     390  int num = 0;
     391
     392
     393#if defined(SH_STANDALONE)
     394  if (num > 0) fputc ('\n', stdout);
     395  fputs (_("Standalone executable"), stdout); ++num;
     396#endif
     397#if defined(SH_WITH_CLIENT)
     398  if (num > 0) fputc ('\n', stdout);
     399  printf (_("Client executable (port %d)"), SH_DEFAULT_PORT); ++num;
     400#endif
     401#if defined(SH_WITH_CLIENT)
     402  if (num > 0) fputc ('\n', stdout);
     403  printf (_("Server executable (port %d, user %s)"),
     404          SH_DEFAULT_PORT, DEFAULT_IDENT);
     405  ++num;
     406#endif
     407
     408  fputs (_(", compiled-in options:"), stdout);
     409
     410#if defined(USE_DL_PREFIX)
     411  if (num > 0) fputc ('\n', stdout);
     412  printf (_(" using system malloc")); ++num;
     413#else
     414  if (num > 0) fputc ('\n', stdout);
     415  printf (_(" using dnmalloc")); ++num;
     416#endif
     417
     418#if defined(HAVE_EGD_RANDOM)
     419  if (num > 0) fputc ('\n', stdout);
     420  printf (_(" using entropy gathering daemon (%s)"), EGD_SOCKET_NAME); ++num;
     421#endif
     422#if defined(HAVE_UNIX_RANDOM)
     423  if (num > 0) fputc ('\n', stdout);
     424  fputs (_(" using unix entropy gatherer"), stdout); ++num;
     425#endif
     426#if defined(HAVE_URANDOM)
     427  if (num > 0) fputc ('\n', stdout);
     428  printf (_(" using entropy device (%s)"), NAME_OF_DEV_RANDOM); ++num;
     429#endif
     430
     431#ifdef WITH_GPG
     432  if (num > 0) fputc ('\n', stdout);
     433  printf (_(" GnuPG signatures (%s)"), DEFAULT_GPG_PATH); ++num;
     434#ifdef HAVE_GPG_CHECKSUM
     435  if (num > 0) fputc ('\n', stdout);
     436  printf (_("   -- GnuPG checksum:  %s"), GPG_HASH); ++num;
     437#endif
     438#ifdef USE_FINGERPRINT
     439  if (num > 0) fputc ('\n', stdout);
     440  printf (_("   -- Key fingerprint: %s"), SH_GPG_FP); ++num;
     441#endif
     442#endif
     443
     444#if defined(SL_DEBUG)
     445  if (num > 0) fputc ('\n', stdout);
     446  fputs (_(" debug build (do not use for production)"), stdout); ++num;
     447#endif
     448#if defined(SCREW_IT_UP)
     449  if (num > 0) fputc ('\n', stdout);
     450  fputs (_(" anti-debugger"), stdout); ++num;
     451#endif
     452#if defined(SH_USE_XML)
     453  if (num > 0) fputc ('\n', stdout);
     454  fputs (_(" xml log format"), stdout); ++num;
     455#endif
     456#if defined(HAVE_NTIME)
     457  if (num > 0) fputc ('\n', stdout);
     458  fputs (_(" using time server"), stdout); ++num;
     459#endif
     460
     461#if defined(SH_WITH_CLIENT) || defined(SH_STANDALONE)
     462#if defined(HAVE_LIBZ)
     463  if (num > 0) fputc ('\n', stdout);
     464  fputs (_(" optionally store full text for files"), stdout); ++num;
     465#endif
     466#if defined(USE_XATTR)
     467  if (num > 0) fputc ('\n', stdout);
     468  fputs (_(" check SELinux attributes"), stdout); ++num;
     469#endif
     470#if defined(USE_ACL)
     471  if (num > 0) fputc ('\n', stdout);
     472  fputs (_(" check Posix ACLs"), stdout); ++num;
     473#endif
     474#if defined(RELOAD_DATABASE)
     475  if (num > 0) fputc ('\n', stdout);
     476  fputs (_(" fetch database on reload"), stdout); ++num;
     477#endif
     478#endif
     479
     480#if defined(SH_WITH_SERVER)
     481
     482#if !defined(HAVE_GETPEEREID) && !defined(SO_PEERCRED) && !defined(HAVE_STRUCT_CMSGCRED) && !defined(HAVE_STRUCT_FCRED) && !(defined(HAVE_STRUCT_SOCKCRED) && defined(LOCAL_CREDS))
     483  if (num > 0) fputc ('\n', stdout);
     484  fputs (_(" command socket authentication: use SetSocketPassword"), stdout);
     485  ++num;
     486#else
     487  if (num > 0) fputc ('\n', stdout);
     488  fputs (_(" command socket authentication: use SetSocketAllowUID"), stdout);
     489  ++num;
     490#endif
     491
     492#if defined(SH_USE_LIBWRAP)
     493  if (num > 0) fputc ('\n', stdout);
     494  fputs (_(" support tcp wrapper"), stdout); ++num;
     495#endif
     496#if defined(INET_SYSLOG)
     497  if (num > 0) fputc ('\n', stdout);
     498  fputs (_(" support listening on 514/udp (syslog)"), stdout); ++num;
     499#endif
     500#endif
     501
     502  if (num == 0)
     503    fputs (_(" none"), stdout);
     504  fputc ('\n', stdout);
     505  return;
     506}
     507
    486508static void sh_getopt_print_modules (void)
    487509{
     
    489511  int num = 0;
    490512 
    491   fputs (_("Compiled-in modules:"), stdout);
     513  fputs (_("Compiled-in modules:\n"), stdout);
    492514#ifdef SH_USE_UTMP
    493515  if (num > 0) fputc (',', stdout);
  • trunk/src/sh_hash.c

    r170 r171  
    15851585      {
    15861586        sl_strlcpy(fullpath, buf->fullpath, MAX_PATH_STORE+1);
    1587         /*
    1588         if (sl_strlen(buf->fullpath) < (MAX_PATH_STORE-3))
    1589           {
    1590             fullpath[MAX_PATH_STORE-2] = '\0';
    1591             fullpath[MAX_PATH_STORE-1] = '\n';
    1592           }
    1593         */
    15941587      }
    15951588    else
  • trunk/src/sh_mail.c

    r170 r171  
    18831883  } querybuf;
    18841884
    1885   querybuf reply;
     1885  querybuf * reply;
    18861886  char expanded[1024];
    18871887  unsigned char * comp_dn, * eom;
     
    18961896    SL_RETURN (NULL, _("get_mx"));
    18971897
     1898  reply = SH_ALLOC(sizeof(querybuf));
     1899
    18981900  errno = 0;
    18991901  length = res_query (hostname, C_IN, T_MX,
    1900                       (unsigned char *) &reply, 4095);
     1902                      (unsigned char *) reply, 4095);
    19011903  if (length < 1)
    19021904    {
     
    19251927#endif
    19261928        }
     1929      SH_FREE(reply);
    19271930      SL_RETURN (NULL, _("get_mx"));
    19281931    }
    19291932
    19301933  ret = 0;
    1931   header  = (HEADER *) &reply;
     1934  header  = (HEADER *) reply;
    19321935
    19331936  /* start of data section
    19341937   */
    1935   comp_dn = (unsigned char *) &reply + HFIXEDSZ;
     1938  comp_dn = (unsigned char *) reply + HFIXEDSZ;
    19361939
    19371940  /* end-of-message
    19381941   */
    1939   eom     = (unsigned char *) &reply + length;
     1942  eom     = (unsigned char *) reply + length;
    19401943
    19411944  /* HEADER NAME  -- must be skipped or decompressed
     
    19581961      comp_dn += ret + QFIXEDSZ;
    19591962      if (ret < 1 || comp_dn >= eom)
    1960         SL_RETURN (NULL, _("get_mx"));
     1963        {
     1964          SH_FREE(reply);
     1965          SL_RETURN (NULL, _("get_mx"));
     1966        }
    19611967    }
    19621968  count         = ntohs (header->ancount);
    19631969  if (count < 1)
    1964     SL_RETURN (NULL, _("get_mx"));
     1970    {
     1971      SH_FREE(reply);
     1972      SL_RETURN (NULL, _("get_mx"));
     1973    }
    19651974
    19661975  retval        = SH_ALLOC (sizeof (dnsrep));
    19671976  if (!retval)
    1968     SL_RETURN (NULL, _("get_mx"));
     1977    {
     1978      SH_FREE(reply);
     1979      SL_RETURN (NULL, _("get_mx"));
     1980    }
     1981
    19691982  retval->count = count;
    19701983
     
    19731986  if (!sl_ok_muls(count, sizeof (mx)))
    19741987    {
     1988      SH_FREE(reply);
    19751989      SH_FREE   (retval);
    19761990      SL_RETURN (NULL, _("get_mx"));
     
    19811995  if (!result)
    19821996    {
     1997      SH_FREE(reply);
    19831998      SH_FREE   (retval);
    19841999      SL_RETURN (NULL, _("get_mx"));
     
    19952010      if (ret < 1 || comp_dn >= eom)
    19962011        {
     2012          SH_FREE(reply);
    19972013          SH_FREE (result);
    19982014          SH_FREE (retval);
     
    20062022      if (type != T_MX || comp_dn >= eom)
    20072023        {
     2024          SH_FREE(reply);
    20082025          SH_FREE (result);
    20092026          SH_FREE (retval);
     
    20172034      if (comp_dn >= eom)
    20182035        {
     2036          SH_FREE(reply);
    20192037          SH_FREE (result);
    20202038          SH_FREE (retval);
     
    20272045      if (comp_dn >= eom)
    20282046        {
     2047          SH_FREE(reply);
    20292048          SH_FREE (result);
    20302049          SH_FREE (retval);
     
    20382057      if (rdlength < 1 || comp_dn >= eom)
    20392058        {
     2059          SH_FREE(reply);
    20402060          SH_FREE (result);
    20412061          SH_FREE (retval);
     
    20492069      if (comp_dn >= eom)
    20502070        {
     2071          SH_FREE(reply);
    20512072          SH_FREE (result);
    20522073          SH_FREE (retval);
     
    20592080      if (ret < 1)
    20602081        {
     2082          SH_FREE(reply);
    20612083          SH_FREE (result);
    20622084          SH_FREE (retval);
     
    20742096  while (ret > 0 && comp_dn < eom && count);
    20752097
     2098  SH_FREE(reply);
    20762099  SL_RETURN (retval, _("get_mx"));
    20772100}
  • trunk/src/sh_portcheck.c

    r170 r171  
    687687  do {
    688688    retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr));
    689   } while (retval < 0 && errno == EINTR);
     689  } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS));
    690690
    691691  if (retval == -1)
     
    775775  do {
    776776    retval = connect(fd, (struct sockaddr *) &sinr, sizeof(sinr));
    777   } while (retval < 0 && errno == EINTR);
     777  } while (retval < 0 && (errno == EINTR || errno == EINPROGRESS));
    778778
    779779  if (retval == -1 && errno == ECONNREFUSED)
  • trunk/src/sh_string.c

    r169 r171  
    44#include <string.h>
    55#include <stdio.h>
     6#include <sys/types.h>
    67
    78#include "sh_string.h"
     
    4041      /* skip leading WS
    4142       */
    42       for (s=e; *s && isspace(*s); ++s) /* nothing */;
     43      for (s=e; *s && isspace((int)*s); ++s) /* nothing */;
    4344
    4445      if (*s)
     
    6566          if (a != line)
    6667            {
    67               /* chop off trailing WS
    68                */
    69               for (a--; isspace(*a) && a > s; a--) /* do nothing */;
    70              
    71               /* terminate string
    72                */
    73               ++a; *a = '\0';
    74             }
     68              if (i < (maxfields -1))
     69                {
     70
     71                  /* chop off trailing WS
     72                   */
     73                  for (a--; isspace((int)*a) && a > s; a--) /* do nothing */;
     74                 
     75                  /* terminate string
     76                   */
     77                  ++a; *a = '\0';
     78                }
     79              else
     80                {
     81                  /* If nfields < actual fields, last string
     82                   * will be remainder, therefore skip to end.
     83                   */
     84                  if ( *a )
     85                    {
     86                      do {
     87                        a++;
     88                      } while ( *a );
     89                    }
     90                }
     91            }
    7592          else
    7693            {
     
    127144      /* skip leading WS
    128145       */
    129       if ( *s && isspace(*s) )
     146      if ( *s && isspace((int)*s) )
    130147        {
    131148          do {
    132149            ++s;
    133           } while ( *s && isspace(*s) );
     150          } while ( *s && isspace((int)*s) );
    134151        }
    135152
     
    142159          do {
    143160            a++;
    144           } while ( *a && (!isspace(*a)) );
     161          } while ( *a && (!isspace((int)*a)) );
    145162
    146163          /* next token, *a is either ws or '\0'
     
    152169          if (i < (maxfields-1))
    153170            {
    154               *a = '\0'; 
     171              *a = '\0';
    155172            }
    156173          else
     
    275292    }
    276293  memcpy(s->str, str, (len+1));
     294  s->len = len;
    277295  return s;
    278296}
     
    397415  sh_string * r = NULL;
    398416  char * p;
     417  long   tlen;
    399418  size_t len;
    400419  int    end    = 0;
     
    403422  size_t newlen = 0;
    404423  long   diff;
    405   int    i;
     424  int    i, curr, last;
    406425
    407426
     
    443462    }
    444463
    445   if (r && ovecnum > 0)
     464
     465  curr = -1;
     466  last = -1;
     467
     468  for (i = 0; i < ovecnum; ++i)
     469    {
     470      if (ovector[2*i] >= 0)
     471        {
     472          curr = i;
     473          break;
     474        }
     475    }
     476 
     477  if (r && ovecnum > 0 && ovector[curr] >= 0)
    446478    {
    447479      r->len = 0; r->str[0] = '\0'; p = r->str;
     
    449481      /* First part, until start of first replacement
    450482       */
    451       memcpy(p, s->str,      ovector[0]); p += ovector[0];
    452       memcpy(p, replacement, rlen);       p += rlen;
    453       *p = '\0'; r->len += (ovector[0] + rlen);
     483      memcpy(p, s->str, (size_t)ovector[curr]); p += ovector[curr];
     484      memcpy(p, replacement,    rlen);       p += rlen;
     485      *p = '\0'; r->len += (ovector[curr] + rlen);
     486
     487      last = curr + 1;
    454488
    455489      for (i = 1; i < ovecnum; ++i)
    456490        {
     491          if (ovector[2*i] < 0)
     492            continue;
     493
     494          curr = 2*i;
     495
    457496          /* From end of last replacement to start of this */
    458           len = ovector[2*i] - ovector[2*i -1];
    459           memcpy(p, &(s->str[ovector[2*i -1]]), len);
    460           p += len;
    461 
    462           /* The replacement */
    463           memcpy(p, replacement, rlen);       
    464           p += rlen;
    465 
    466           /* null terminate */
    467           *p = '\0'; r->len += (len + rlen);
    468         }
     497          tlen = (long)(ovector[curr] - ovector[last]);
     498          if (tlen >= 0)
     499            {
     500              len = (size_t) tlen;
     501
     502              if (tlen > 0)
     503                {
     504                  memcpy(p, &(s->str[ovector[last]]), (size_t)len);
     505                  p += len;
     506                }
     507             
     508              /* The replacement */
     509              memcpy(p, replacement, rlen);       
     510              p += rlen;
     511             
     512              /* null terminate */
     513              *p = '\0'; r->len += (len + rlen);
     514
     515              last = curr + 1;
     516            }
     517        }
    469518
    470519      /* Last part, after last replacement; includes terminating null
    471520       */
    472       len = (s->len + 1) - ovector[2*i -1];
    473       memcpy(p, &(s->str[ovector[2*i -1]]), len);
    474       p += len; *p = '\0'; r->len += (len - 1);
    475     }
     521      if (last > 0)
     522        {
     523          /* If not, nothing has been replaced, and r is still a copy of s
     524           */
     525          tlen = (long)((s->len + 1) - ovector[last]);
     526          if (tlen > 0)
     527            {
     528              len = (size_t)tlen;
     529              memcpy(p, &(s->str[ovector[2*i -1]]), (size_t)len);
     530              p += len; *p = '\0'; r->len += (len - 1);
     531            }
     532        }
     533
     534    }
     535
    476536  return r;
    477537}
     
    785845  t = sh_string_replace(s, ovector, ovecnum,
    786846                        "___", 3);
     847  CuAssertPtrNotNull(tc, t);
    787848  CuAssertStrEquals(tc, "___c ___ ",   t->str);
    788849  CuAssertIntEquals(tc, 9, (int)t->len);
     
    792853  t = sh_string_replace(s, ovector, ovecnum,
    793854                        "___", 3);
     855  CuAssertPtrNotNull(tc, t);
    794856  CuAssertStrEquals(tc, "___c ___",   t->str);
    795857  CuAssertIntEquals(tc, 8, (int)t->len);
     
    806868                        "___", 3);
    807869 
     870  CuAssertPtrNotNull(tc, t);
    808871  CuAssertStrEquals(tc, "______f ghi ",   t->str);
    809872  CuAssertIntEquals(tc, 12, (int)t->len);
     
    813876  t = sh_string_replace(s, ovector, ovecnum,
    814877                        "___", 3);
     878  CuAssertPtrNotNull(tc, t);
    815879  CuAssertStrEquals(tc, "abc ___ef ghi___",   t->str);
    816880  CuAssertIntEquals(tc, 16, (int)t->len);
     
    818882  t = sh_string_replace(s, ovector, 0,
    819883                        "___", 3);
     884  CuAssertPtrNotNull(tc, t);
    820885  CuAssertStrEquals(tc, s->str,   t->str);
    821886  CuAssertIntEquals(tc, (int)s->len, (int)t->len);
  • trunk/src/sh_tiger0.c

    r170 r171  
    843843  static const int BLOCKSIZE = 8192;
    844844  struct md5_ctx ctx;
    845   char buffer[8264]; /* BLOCKSIZE + 72  AIX compiler chokes */
     845  char * buffer = SH_ALLOC(8264); /* BLOCKSIZE + 72  AIX compiler chokes */
    846846  size_t sum;
    847847
     
    870870      SH_FREE(tmp);
    871871      *Length = 0;
     872      SH_FREE(buffer);
    872873      return -1;
    873874    }
     
    878879
    879880  /* Iterate over full file contents.  */
    880   while (1 == 1) {
     881  while (1) {
    881882    /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
    882883       computation function processes the whole buffer so that with the
     
    894895        {
    895896          if (sig_termfast == 1)
    896             return -1;
     897            {
     898              SH_FREE(buffer);
     899              return -1;
     900            }
    897901          TPT((0, FIL__ , __LINE__ , _("msg=<SL_ISERROR (%ld)>\n"), n));
    898902          tmp = sh_util_safe_name (filename);
     
    909913          SH_FREE(tmp);
    910914          *Length = 0;
     915          SH_FREE(buffer);
    911916          return -1;
    912917        }
     
    953958      {
    954959        *Length = 0;
     960        SH_FREE(buffer);
    955961        return -1;
    956962      }
     
    969975
    970976  *Length = bcount;
     977  SH_FREE(buffer);
    971978  return 0;
    972979}
     
    13671374  static const int BLOCKSIZE = 4096;
    13681375  struct sha_ctx ctx;
    1369   char buffer[4168]; /* BLOCKSIZE + 72 AIX compiler chokes */
     1376  char * buffer = SH_ALLOC(4168); /* BLOCKSIZE + 72 AIX compiler chokes */
    13701377  off_t sum = 0;
    13711378  char * tmp;
     
    13931400      SH_FREE(tmp);
    13941401      *Length = 0;
     1402      SH_FREE(buffer);
    13951403      return -1;
    13961404    }
     
    14171425        {
    14181426          if (sig_termfast == 1)
    1419             return -1;
     1427            {
     1428              SH_FREE(buffer);
     1429              return -1;
     1430            }
    14201431
    14211432          TPT((0, FIL__ , __LINE__ , _("msg=<SL_ISERROR (%ld)>\n"), n));
     
    14351446          SH_FREE(tmp);
    14361447          *Length = 0;
     1448          SH_FREE(buffer);
    14371449          return -1;
    14381450        }
     
    14791491      {
    14801492        *Length = 0;
     1493        SH_FREE(buffer);
    14811494        return -1;
    14821495      }
     
    14971510  sha_digest (&ctx, resblock);
    14981511  *Length = bcount;
     1512  SH_FREE(buffer);
    14991513  return 0;
    15001514}
     
    15051519                                   char * out, size_t len)
    15061520{
    1507   int cnt = (int) Length;  /* fix compiler warning */
     1521  int cnt;
    15081522  char outbuf[KEY_LEN+1];
    15091523  unsigned char sha1buffer[20];
  • trunk/src/sh_tiger1_64.c

    r170 r171  
    371371}
    372372
    373 void tiger_compress(word64 *str, word64 state[3])
     373void tiger_compress(const word64 *str, word64 state[3])
    374374{
    375375  tiger_compress_macro(((word64*)str), ((word64*)state));
    376376}
    377377
    378 void tiger_t(word64 *str, word64 length, word64 res[3])
     378void tiger_t(const word64 *str, word64 length, word64 res[3])
    379379{
    380380  register word64 i;
  • trunk/src/sh_tools.c

    r170 r171  
    725725  struct  sigaction  new_act;
    726726  struct  sigaction  old_act;
    727 #if defined(WITH_TPT)
    728727  char    errbuf[SH_ERRBUF_SIZE];
    729 #endif
    730728
    731729  SL_ENTER(_("sh_write_select"));
     
    762760                continue;
    763761              }
    764             if ( errno == EINTR) /* try again */
     762            if ( errno == EINTR || errno == EINPROGRESS ) /* try again */
    765763              continue;
    766764            *w_error = errno;
    767             TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"),
    768                   sh_error_message(*w_error, errbuf, sizeof(errbuf))));
    769765            sigaction (SIGPIPE, &old_act, NULL);
     766            sh_error_message(*w_error, errbuf, sizeof(errbuf));
     767            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     768                             errbuf,
     769                             _("sh_write_select (ws)") );
     770            TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), errbuf ));
    770771            SL_RETURN( countbytes, _("sh_write_select"));
    771772          }
     
    780781                continue;
    781782              }
    782             if ( errno == EINTR ) /* try again */
     783            if ( errno == EINTR || errno == EINPROGRESS ) /* try again */
    783784              continue;
    784785            *w_error = errno;
    785             TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"),
    786                   sh_error_message(*w_error, errbuf, sizeof(errbuf))));
    787786            sigaction (SIGPIPE, &old_act, NULL);
     787            sh_error_message(*w_error, errbuf, sizeof(errbuf));
     788            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     789                             errbuf,
     790                             _("sh_write_select (rs)") );
     791            TPT(( 0, FIL__, __LINE__, _("msg=<select: %s>\n"), errbuf ));
    788792            SL_RETURN( countbytes, _("sh_write_select"));
    789793          }
     
    836840            *w_error = errno;
    837841            sigaction (SIGPIPE, &old_act, NULL);
     842            sh_error_message(*w_error, errbuf, sizeof(errbuf));
     843            sh_error_handle (SH_ERR_INFO, FIL__, __LINE__, errno, MSG_E_SUBGEN,
     844                             errbuf,
     845                             (type == SH_DO_WRITE) ?
     846                             _("sh_write_select (w)") : _("sh_write_select (r)"));
    838847            TPT(( 0, FIL__, __LINE__, _("msg=<count < 0>\n")));
    839848            SL_RETURN( countbytes, _("sh_write_select"));
  • trunk/src/sh_unix.c

    r170 r171  
    37733773        {
    37743774#ifdef HAVE_LIBZ
    3775           unsigned long   clen = compressBound(sh_string_len(content));
    3776           unsigned char * compressed = SH_ALLOC(clen);
     3775          unsigned long   clen;
     3776          unsigned char * compressed;
     3777#ifdef HAVE_COMPRESSBOUND
     3778          clen       = compressBound(sh_string_len(content));
     3779#else
     3780          if (sh_string_len(content) > 10*SH_TXT_MAX)
     3781            clen = SH_TXT_MAX;
     3782          else
     3783            clen = 13 + (int)(1.0001*sh_string_len(content));
     3784#endif
     3785          compressed = SH_ALLOC(clen);
    37773786          if (Z_OK == compress(compressed, &clen,
    37783787                               (unsigned char *) sh_string_str(content),
  • trunk/src/trustfile.c

    r170 r171  
    782782          register int i;               /* trustworthy or not?       */
    783783          const char * t_const;
     784          char *end;
    784785
    785786          /*
     
    810811          if (csym[0] != '/')
    811812            {
     813              /* pointer to one above last element
     814               */
     815              end = &full[MAXFILENAME-1]; ++end;
     816
    812817              /* initialize pointers
    813818               */
     
    817822               */
    818823              t = fexp;
    819               while(*t && b < &full[MAXFILENAME])
     824              while(*t && b < end)
    820825                *b++ = *t++;
    821826
     
    823828               */
    824829              t_const = "/../";
    825               while(*t && b < &full[MAXFILENAME])
     830              while(*t && b < end)
    826831                *b++ = *t_const++;
    827832
     
    829834               */
    830835              t = csym;
    831               while(*t && b < &full[MAXFILENAME])
     836              while(*t && b < end)
    832837                *b++ = *t++;
    833838
    834839              /* see if we're too big
    835840               */
    836               if (*t || b == &full[MAXFILENAME])
     841              if (*t || b == end)
    837842                {
    838843                  /* yes -- error
Note: See TracChangeset for help on using the changeset viewer.