Changeset 247 for trunk


Ignore:
Timestamp:
Sep 17, 2009, 10:22:48 PM (15 years ago)
Author:
katerina
Message:

Fix a race condition that might have caused ticket #163.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r242 r247  
    1212dnl start
    1313dnl
    14 AM_INIT_AUTOMAKE(samhain, 2.5.8a)
     14AM_INIT_AUTOMAKE(samhain, 2.5.9a)
    1515AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1616AC_CANONICAL_HOST
  • trunk/docs/Changelog

    r246 r247  
    1 2.5.9:
     12.5.9a:
     2        * fixed a race condition in closing of file handles
     3
     42.5.9 (11-09-2009):
    25        * added code to generate directory for pid file, since it
    36          would get cleaned if /var/run is a tmpfs mount (problem
     
    58        * fixed a bug that prevented reporting of user/executable path
    69          for open UDP ports (issue reported by N. Rath)
    7 
    8 2.5.8a:
     10        * added more debugging code
     11
     122.5.8a (18-08-2009):
    913        * fixed a bug in sh_files.c that would prevent samhain from
    1014          running on MacOS X (reported by David)
    1115
    12 2.5.8:
     162.5.8 (06-08-2009):
    1317        * fixed a bug in the MX resolver routine which causes it to fail
    1418          sometimes (issue reported by N. Rath).
  • trunk/src/sh_extern.c

    r235 r247  
    391391                      _exit(EXIT_FAILURE);
    392392                    }
     393
    393394                  pfd = get_the_fd(fd);
     395
     396                  do {
     397                    val_return = dup (pfd);
     398                  } while (val_return < 0 && errno == EINTR);
     399                  pfd = val_return;
     400                  if (pfd < 0)
     401                    {
     402                      PDBGC_S("fexecve: dup (2) failed");
     403                      _exit(EXIT_FAILURE);
     404                    }
     405                  sl_close(fd);
     406                  fd = -1;
    394407                }
    395408#endif
     
    426439                sl_close(fd);
    427440              else if (pfd != -1)
    428                 close(fd);
     441                close(pfd);
    429442            }
    430443#endif
  • trunk/src/sh_gpg.c

    r227 r247  
    263263
    264264#if defined(HAVE_GPG_CHECKSUM)
    265   SL_TICKET   checkfd;
     265  SL_TICKET   checkfd = -1;
    266266  int         myrand;
    267267  int         i;
     
    560560       */
    561561      sl_close(checkfd);
     562      checkfd = -1;
    562563#endif
    563564
  • trunk/src/sh_hash.c

    r227 r247  
    820820    }
    821821
    822   sh_fin_fd = fdopen(get_the_fd(fd), "rb");
     822  sh_fin_fd = fdopen(dup(get_the_fd(fd)), "rb");
    823823  if (!sh_fin_fd)
    824824    {
     
    11281128#if defined(WITH_GPG) || defined(WITH_PGP)
    11291129  extern int get_the_fd (SL_TICKET ticket);
    1130   FILE *   fin_cp;
     1130  FILE *   fin_cp = NULL;
    11311131
    11321132  char * buf  = NULL;
     
    12431243  fdTmp = open_tmp();
    12441244
    1245   fin_cp = fdopen(get_the_fd(fd), "rb");
     1245  fin_cp = fdopen(dup(get_the_fd(fd)), "rb");
    12461246  buf = SH_ALLOC(FGETS_BUF);
    12471247
  • trunk/src/sh_unix.c

    r246 r247  
    12791279    fdlimit = 65536;
    12801280
     1281  if (!inchild)
     1282    sl_dropall (fdx, except);
     1283  else
     1284    sl_dropall_dirty (fdx, except);
     1285
    12811286  /* Close everything from fd (inclusive) up to fdlimit (exclusive).
    12821287   */
     
    12901295        close(fd++);
    12911296    }
    1292 
    1293   if (!inchild)
    1294     sl_dropall (fdx, except);
    1295   else
    1296     sl_dropall_dirty (fdx, except);
    12971297
    12981298  SL_RET0(_("sh_unix_closeall"));
  • trunk/src/slib.c

    r243 r247  
    16741674  if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
    16751675    {
    1676       free(ofiles[fd]);
     1676      free (ofiles[fd]);
    16771677      ofiles[fd] = NULL;
    16781678      SL_IRETURN(SL_EMEM, _("sl_make_ticket"));
     
    16871687      (void) free (ofiles[fd]->path);
    16881688      (void) free (ofiles[fd]);
     1689      ofiles[fd] = NULL;
    16891690      SL_IRETURN(ticket, _("sl_make_ticket"));
    16901691    }
     
    19351936  if ( (ofiles[fd]->path = (char *) malloc(len) ) == NULL)
    19361937    {
    1937       free(ofiles[fd]);
     1938      free (ofiles[fd]);
    19381939      ofiles[fd] = NULL;
    19391940      close(fd);
     
    19491950      (void) free (ofiles[fd]->path);
    19501951      (void) free (ofiles[fd]);
     1952      ofiles[fd] = NULL;
    19511953      close(fd);
    19521954      SL_IRETURN(ticket, _("sl_open_file"));
     
    22092211    SL_IRETURN(fd, _("sl_close"));
    22102212
     2213  if (ofiles[fd] != NULL)
     2214    {
    22112215#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_MINCORE) && defined(POSIX_FADV_DONTNEED)
    2212 
    2213   if (ofiles[fd]->flush == SL_TRUE)
    2214     {
    2215       posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
    2216     }
    2217 
    2218 #endif
     2216      if (ofiles[fd]->flush == SL_TRUE)
     2217        {
     2218          posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
     2219        }
     2220#endif
     2221      if (ofiles[fd]->content)
     2222        sh_string_destroy(&(ofiles[fd]->content));
     2223      (void) free (ofiles[fd]->path);
     2224      (void) free (ofiles[fd]);
     2225      ofiles[fd] = NULL;
     2226    }
    22192227
    22202228  /* This may fail, but what to do then ?
    22212229   */
    2222   if (0 != close(fd) && ofiles[fd] != NULL)
     2230  if (0 != close(fd))
    22232231    {
    22242232      TPT((0, FIL__, __LINE__,
    2225            _("msg=<Error closing file.>, path=<%s>, fd=<%d>, err=<%s>\n"),
    2226            ofiles[fd]->path, fd, strerror(errno)));
    2227     }
    2228 
    2229   if (ofiles[fd] != NULL)
    2230     {
    2231       if (ofiles[fd]->content)
    2232         sh_string_destroy(&(ofiles[fd]->content));
    2233       (void) free(ofiles[fd]->path);
    2234       (void) free(ofiles[fd]);
    2235       ofiles[fd] = NULL;
     2233           _("msg=<Error closing file.>, fd=<%d>, err=<%s>\n"),
     2234           fd, strerror(errno)));
    22362235    }
    22372236
     
    22482247            sh_string_destroy(&(ofiles[fd]->content));
    22492248          if (ofiles[fd]->path != NULL)
    2250             (void) free(ofiles[fd]->path);
    2251           (void) free(ofiles[fd]);
     2249            (void) free (ofiles[fd]->path);
     2250          (void) free (ofiles[fd]);
    22522251          ofiles[fd] = NULL;
    22532252        }
Note: See TracChangeset for help on using the changeset viewer.