X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_regex%2Fos_match_execute.c;h=0bc8377f5dd04eb6f2f3fee3241953fbaf913cfb;hb=789cbc8e52da68eba3517b920ef22e000cf3c9fd;hp=70f31842a4cd94e8a7998c2c169daa5d9d1d9a79;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/os_regex/os_match_execute.c b/src/os_regex/os_match_execute.c index 70f3184..0bc8377 100755 --- a/src/os_regex/os_match_execute.c +++ b/src/os_regex/os_match_execute.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 */ @@ -19,10 +19,13 @@ /** Internal matching **/ -int _OS_Match(char *pattern, char *str, int str_len, int size) +int _OS_Match(const char *pattern, const char *str, size_t str_len, size_t size) { - int i = 0,j; - char *pt = pattern; + size_t i = 0,j; + const char *pt = pattern; + + if(str_len < size) + return(FALSE); size = str_len - size; @@ -39,10 +42,10 @@ int _OS_Match(char *pattern, char *str, int str_len, int size) { if(str[j] == '\0') return(FALSE); - + else if(*pt != charmap[(uchar)str[j]]) { - pt = pattern; + pt = pattern; goto nnext; } j++;pt++; @@ -58,40 +61,50 @@ int _OS_Match(char *pattern, char *str, int str_len, int size) /** Internal matching **/ -int _os_strncmp(char *pattern, char *str, int str_len, int size) +int _os_strncmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, size_t size) { if(strncasecmp(pattern, str, size) == 0) return(TRUE); - - return(FALSE); + + return(FALSE); } /** Internal matching **/ -int _os_strcmp(char *pattern, char *str, int str_len, int size) +int _os_strcmp(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) { if(strcasecmp(pattern, str) == 0) return(TRUE); - - return(FALSE); + + return(FALSE); } -int _os_strmatch(char *pattern, char *str, int str_len, int size) +int _os_strmatch(__attribute__((unused)) const char *pattern, __attribute__((unused)) const char *str, + __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) { return(TRUE); } +int _os_strstr(const char *pattern, const char *str, __attribute__((unused)) size_t str_len, __attribute__((unused)) size_t size) +{ + if(strstr(str, pattern) != NULL) + { + return(TRUE); + } + return(FALSE); +} + /** Internal matching **/ -int _os_strcmp_last(char *pattern, char *str, int str_len, int size) +int _os_strcmp_last(const char *pattern, const char *str, size_t str_len, size_t size) { /* Size of the string must be bigger */ - if((str_len - size) < 0) + if(str_len < size) return(FALSE); - + if(strcasecmp(pattern, str + (str_len - size)) == 0) return(TRUE); - - return(FALSE); + + return(FALSE); } @@ -101,10 +114,10 @@ int _os_strcmp_last(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_Execute(char *str, int str_len, OSMatch *reg) +int OSMatch_Execute(const char *str, size_t str_len, OSMatch *reg) { short int i = 0; - + /* The string can't be NULL */ if(str == NULL) { @@ -116,9 +129,9 @@ int OSMatch_Execute(char *str, int str_len, OSMatch *reg) /* Looping on all sub patterns */ while(reg->patterns[i]) { - if(reg->match_fp[i](reg->patterns[i], - str, - str_len, + if(reg->match_fp[i](reg->patterns[i], + str, + str_len, reg->size[i]) == TRUE) { return(1); @@ -127,7 +140,7 @@ int OSMatch_Execute(char *str, int str_len, OSMatch *reg) } return(0); -} +} /* EOF */