Changeset 438 for trunk


Ignore:
Timestamp:
Aug 29, 2013, 8:37:23 PM (11 years ago)
Author:
katerina
Message:

Fix for ticket #342 (IgnoreAdded et al. matching)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_ignore.c

    r425 r438  
    3333#endif
    3434
     35#include <string.h>
     36
    3537#include "samhain.h"
    3638#include "sh_mem.h"
     
    5961{
    6062  struct sh_ignore_list * new;
     63  char                  * reg_expr;
     64  size_t                  len;
     65
    6166#ifdef HAVE_REGEX_H
    6267  int                     status = -1;
     
    6873  SL_ENTER(_("sh_ignore_add"));
    6974
    70   if (addpath == NULL)
     75  if ( (addpath == NULL) || (sl_ok_adds(2, strlen(addpath)) == SL_FALSE) )
    7176    {
    7277      SL_RETURN(list, _("sh_ignore_add"));
    7378    }
    7479
    75   new  = SH_ALLOC(sizeof(struct sh_ignore_list));
    76 
    77 #ifdef HAVE_REGEX_H
    78   status = regcomp(&(new->preg), addpath, REG_NOSUB|REG_EXTENDED);
     80  new      = SH_ALLOC(sizeof(struct sh_ignore_list));
     81
     82  len      = 2 + strlen(addpath);
     83  reg_expr = SH_ALLOC(len);
     84  sl_strlcpy(reg_expr,     "^", len);
     85  sl_strlcat(reg_expr, addpath, len);
     86
     87#ifdef HAVE_REGEX_H
     88  status = regcomp(&(new->preg), reg_expr, REG_NOSUB|REG_EXTENDED);
    7989  if (status != 0) 
    8090    {
     
    8393      errbuf[BUFSIZ] = '\0';
    8494      sh_error_handle ((-1), FIL__, __LINE__, status, MSG_E_REGEX,
    85                        errbuf, addpath);
     95                       errbuf, reg_expr);
    8696      SH_FREE(errbuf);
    8797      SH_FREE(new);
     98      SH_FREE(reg_expr);
    8899      SL_RETURN(list, _("sh_ignore_add"));
    89100    }
     
    94105#endif
    95106
     107  SH_FREE(reg_expr);
    96108  new->next = list;
    97109
     
    253265  CuAssertTrue(tc, S_FALSE == ret);
    254266
     267  ret = sh_ignore_chk_del ("/my/var/log/foo/test");
     268  CuAssertTrue(tc, S_FALSE == ret);
     269
    255270  sh_ignore_clean();
    256271  CuAssertTrue(tc, NULL == sh_del_ign);
     
    274289  CuAssertTrue(tc, S_FALSE == ret);
    275290
     291  ret = sh_ignore_chk_new ("/my/var/log/foo/test");
     292  CuAssertTrue(tc, S_FALSE == ret);
     293
    276294  sh_ignore_clean();
    277295  CuAssertTrue(tc, NULL == sh_new_ign);
     
    295313  CuAssertTrue(tc, S_FALSE == ret);
    296314
     315  ret = sh_ignore_chk_mod ("/my/var/log/foo/test");
     316  CuAssertTrue(tc, S_FALSE == ret);
     317
    297318  sh_ignore_clean();
    298319  CuAssertTrue(tc, NULL == sh_new_ign);
Note: See TracChangeset for help on using the changeset viewer.