Ignore:
Timestamp:
Oct 26, 2025, 12:17:47 PM (16 hours ago)
Author:
katerina
Message:

Fix for ticket #476 (move logfile monitoring module from PCRE to PCRE2).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_log_correlate.c

    r481 r588  
    99#include <time.h>
    1010
    11 /* Debian/Ubuntu: libpcre3-dev */
    12 #ifdef HAVE_PCRE_PCRE_H
    13 #include <pcre/pcre.h>
     11/* Debian/Ubuntu: libpcre2-dev */
     12#define PCRE2_CODE_UNIT_WIDTH 8
     13#ifdef HAVE_PCRE2_PCRE2_H
     14#include <pcre2/pcre2.h>
    1415#else
    15 #include <pcre.h>
     16#include <pcre2.h>
    1617#endif
    1718
    18 #ifndef PCRE_NO_AUTO_CAPTURE
    19 #define PCRE_NO_AUTO_CAPTURE 0
    20 #endif
    2119
    2220#include "samhain.h"
     
    173171{
    174172  sh_string       * label;           /* label of match rule     */
    175   pcre            * rule;            /* compiled regex for rule */
     173  pcre2_code      * rule;            /* compiled regex for rule */
    176174  time_t            reported;        /* last reported           */
    177175  struct sh_qeval * queue;           /* assigned queue          */
     
    208206    {
    209207      struct sh_mkeep * mkeep = SH_ALLOC(sizeof(struct sh_mkeep));
    210       const char * error;
    211       int          erroffset;
     208      int              error;
     209      size_t            erroffset;
    212210      struct sh_qeval * rqueue = NULL;
    213211
    214       mkeep->rule = pcre_compile(pattern, PCRE_NO_AUTO_CAPTURE,
    215                              &error, &erroffset, NULL);
     212      mkeep->rule = pcre2_compile((PCRE2_SPTR8)pattern, PCRE2_ZERO_TERMINATED, PCRE2_NO_AUTO_CAPTURE,
     213                                  &error, &erroffset, NULL);
    216214      if (!(mkeep->rule))
    217215        {
     
    239237          if (!rqueue)
    240238            {
    241               pcre_free(mkeep->rule);
     239              pcre2_code_free(mkeep->rule);
    242240              SH_FREE(splits);
    243241              SH_FREE(mkeep);
     
    264262      mkeep_list = mkeep->next;
    265263      sh_string_destroy(&(mkeep->label));
    266       pcre_free(mkeep->rule);
     264      pcre2_code_free(mkeep->rule);
    267265      mkeep = mkeep_list;
    268266    }
     
    286284          while (mkeep)
    287285            {
    288               /* Use pcre_dfa_exec() to obtain number of matches. Needs ovector
    289                * array, otherwise number of matches is not returned.
    290                */
    291 #if defined(HAVE_PCRE_DFA_EXEC)
    292               int ovector[SH_MINIBUF];
    293               int wspace[SH_MINIBUF];
    294 #endif
    295 
    296 #if defined(HAVE_PCRE_DFA_EXEC)
    297               int val = pcre_dfa_exec(mkeep->rule, NULL,
    298                                       sh_string_str(res),
    299                                       (int)sh_string_len(res),
    300                                       0, /* start at offset 0 in the subject */
    301                                       0,
    302                                       ovector, SH_MINIBUF,
    303                                       wspace, SH_MINIBUF);
    304 #else
    305               int val = pcre_exec(mkeep->rule, NULL,
    306                                   sh_string_str(res),
    307                                   (int)sh_string_len(res),
    308                                   0, /* start at offset 0 in the subject */
    309                                   0,
    310                                   NULL, 0);
    311               val = (val >= 0) ? 1 : val;                             
    312 #endif
    313 
    314               if (val >= 0)
     286              pcre2_match_data * match_data = pcre2_match_data_create_from_pattern(mkeep->rule, NULL);
     287             
     288              int val = pcre2_match(mkeep->rule,
     289                                    (PCRE2_SPTR8) sh_string_str(res), (int)sh_string_len(res), 0,
     290                                    0, match_data, NULL);
     291             
     292              pcre2_match_data_free(match_data);
     293             
     294              if (val > 0)
    315295                {
    316296                  sh_string * alias;
Note: See TracChangeset for help on using the changeset viewer.