X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_regex%2Fos_match_compile.c;h=bf1c951f76b2e85f6e3bb56aed4752f10f2a5073;hb=927951d1c1ad45ba9e7325f07d996154a91c911b;hp=8521b3f11bd3ab68f4868ca1b218b0de494a4af1;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/os_regex/os_match_compile.c b/src/os_regex/os_match_compile.c index 8521b3f..bf1c951 100755 --- a/src/os_regex/os_match_compile.c +++ b/src/os_regex/os_match_compile.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -18,14 +18,6 @@ #include "os_regex.h" #include "os_regex_internal.h" -/* Prototype fo the _OsMatch */ -int _OS_Match(char *pattern, char *str, int str_len, int size); -int _os_strncmp(char *pattern, char *str, int str_len, int size); -int _os_strcmp_last(char *pattern, char *str, int str_len, int size); -int _os_strcmp(char *pattern, char *str, int str_len, int size); -int _os_strmatch(char *pattern, char *str, int str_len, int size); - - /** int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) v0.1 * Compile a pattern to be used later. * Allowed flags are: @@ -33,28 +25,30 @@ int _os_strmatch(char *pattern, char *str, int str_len, int size); * Returns 1 on success or 0 on error. * The error code is set on reg->error. */ -int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) +int OSMatch_Compile(const char *pattern, OSMatch *reg, int flags) { - int i = 0; - int count = 0; + int usstrstr = 0; + size_t i = 0; + size_t count = 0; int end_of_string = 0; - + char *pt; char *new_str; char *new_str_free = NULL; - + /* Checking for references not initialized */ if(reg == NULL) { return(0); } - + /* Initializing OSRegex structure */ reg->error = 0; reg->patterns = NULL; reg->size = NULL; + reg->match_fp = NULL; /* The pattern can't be null */ @@ -71,8 +65,8 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) reg->error = OS_REGEX_MAXSIZE; goto compile_error; } - - + + /* Duping the pattern for our internal work */ new_str = strdup(pattern); if(!new_str) @@ -82,35 +76,40 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) } new_str_free = new_str; pt = new_str; - - + + + /* Getting the number of sub patterns */ while(*pt != '\0') { - /* The pattern must be always lower case if + /* The pattern must be always lower case if * case sensitive is set */ if(!(flags & OS_CASE_SENSITIVE)) { - *pt = charmap[(uchar)*pt]; + *pt = (char) charmap[(uchar)*pt]; } - - /* Number of sub patterns */ + + /* Number of sub patterns */ if(*pt == OR) { count++; } - pt++; + else if(*pt == -29) + { + usstrstr = 1; + } + pt++; } - - + + /* For the last pattern */ count++; - reg->patterns = calloc(count +1, sizeof(char *)); - reg->size = calloc(count +1, sizeof(int)); - reg->match_fp = calloc(count +1, sizeof(void *)); - - + reg->patterns = (char **) calloc(count +1, sizeof(char *)); + reg->size = (size_t *) calloc(count +1, sizeof(size_t)); + reg->match_fp = (int (**)(const char *, const char *, size_t, size_t)) calloc(count +1, sizeof(void *)); + + /* Memory allocation error check */ if(!reg->patterns || !reg->size || !reg->match_fp) { @@ -127,12 +126,12 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) reg->size[i] = 0; } i = 0; - - + + /* Reassigning pt to the beginning of the string */ pt = new_str; - + /* Getting the sub patterns */ do { @@ -148,7 +147,7 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) /* Dupping the string */ if(*new_str == BEGINREGEX) reg->patterns[i] = strdup(new_str +1); - else + else reg->patterns[i] = strdup(new_str); /* Memory error */ @@ -179,13 +178,20 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) reg->size[i] = strlen(reg->patterns[i]) -1; reg->patterns[i][reg->size[i]] = '\0'; } - + /* If string starts with ^, use strncmp */ else if(*new_str == BEGINREGEX) { reg->match_fp[i] = _os_strncmp; reg->size[i] = strlen(reg->patterns[i]); } + + else if(usstrstr == 1) + { + reg->match_fp[i] = _os_strstr; + reg->size[i] = strlen(reg->patterns[i]); + } + else { reg->match_fp[i] = _OS_Match; @@ -209,16 +215,16 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) /* Success return */ free(new_str_free); return(1); - - + + /* Error handling */ compile_error: - + if(new_str_free) { free(new_str_free); } - + OSMatch_FreePattern(reg); return(0);