X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_regex%2Fos_regex_compile.c;h=d961b2abb343f8b50dcf91bfc008f66673dc9e7a;hb=789cbc8e52da68eba3517b920ef22e000cf3c9fd;hp=10ae1545d4ba12af76720700cda2800dca334e92;hpb=ef70704f0b31b59bb719b884d6a99cb9e3e2044a;p=ossec-hids.git diff --git a/src/os_regex/os_regex_compile.c b/src/os_regex/os_regex_compile.c index 10ae154..d961b2a 100755 --- a/src/os_regex/os_regex_compile.c +++ b/src/os_regex/os_regex_compile.c @@ -27,14 +27,14 @@ * Returns 1 on success or 0 on error. * The error code is set on reg->error. */ -int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) +int OSRegex_Compile(const char *pattern, OSRegex *reg, int flags) { - int i = 0; - int count = 0; + size_t i = 0; + size_t count = 0; int end_of_string = 0; int parenthesis = 0; - int prts_size = 0; - int max_prts_size = 0; + unsigned prts_size = 0; + unsigned max_prts_size = 0; char *pt; char *new_str; @@ -90,26 +90,6 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) if(*pt == BACKSLASH) { pt++; - if(!((*pt == 'w') || - (*pt == 'W') || - (*pt == 's') || - (*pt == 'S') || - (*pt == 'd') || - (*pt == 'D') || - (*pt == '.') || - (*pt == '(') || - (*pt == ')') || - (*pt == 'p') || - (*pt == 't') || - (*pt == '$') || - (*pt == '|') || - (*pt == '<') || - (*pt == '\\'))) - { - reg->error = OS_REGEX_BADREGEX; - goto compile_error; - } - /* Giving the new values for each regex */ switch(*pt) { @@ -128,6 +108,9 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) case '$': *pt = 13;break; case '|': *pt = 14;break; case '<': *pt = 15;break; + default: + reg->error = OS_REGEX_BADREGEX; + goto compile_error; } pt++; @@ -157,7 +140,7 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) */ if(!(flags & OS_CASE_SENSITIVE)) { - *pt = charmap[(uchar)*pt]; + *pt = (char) charmap[(uchar)*pt]; } if(*pt == OR) @@ -184,15 +167,22 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) /* Allocating the memory for the sub patterns */ count++; - reg->patterns = calloc(count +1, sizeof(char *)); - reg->flags = calloc(count +1, sizeof(int)); + reg->patterns = (char **) calloc(count +1, sizeof(char *)); + reg->flags = (int *) calloc(count +1, sizeof(int)); + + /* Memory allocation error check */ + if(!reg->patterns || !reg->flags) + { + reg->error = OS_REGEX_OUTOFMEMORY; + goto compile_error; + } /* For the substrings */ if((prts_size > 0) && (flags & OS_RETURN_SUBSTRING)) { - reg->prts_closure = calloc(count +1, sizeof(char **)); - reg->prts_str = calloc(count +1, sizeof(char **)); + reg->prts_closure = (const char ***) calloc(count +1, sizeof(const char **)); + reg->prts_str = (const char ***) calloc(count +1, sizeof(const char **)); if(!reg->prts_closure || !reg->prts_str) { reg->error = OS_REGEX_OUTOFMEMORY; @@ -201,13 +191,6 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) } - /* Memory allocation error check */ - if(!reg->patterns || !reg->flags) - { - reg->error = OS_REGEX_OUTOFMEMORY; - goto compile_error; - } - /* Initializing each sub pattern */ for(i = 0; i<=count; i++) { @@ -268,7 +251,7 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) /* The parenthesis closure if set */ if(reg->prts_closure) { - int tmp_int = 0; + unsigned tmp_int = 0; char *tmp_str; @@ -299,8 +282,8 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) } /* Allocating the memory */ - reg->prts_closure[i] = calloc(prts_size + 1, sizeof(char *)); - reg->prts_str[i] = calloc(prts_size + 1, sizeof(char *)); + reg->prts_closure[i] = (const char **) calloc(prts_size + 1, sizeof(const char *)); + reg->prts_str[i] = (const char **) calloc(prts_size + 1, sizeof(const char *)); if((reg->prts_closure[i] == NULL)||(reg->prts_str[i] == NULL)) { reg->error = OS_REGEX_OUTOFMEMORY; @@ -345,7 +328,7 @@ int OSRegex_Compile(char *pattern, OSRegex *reg, int flags) }while(!end_of_string); /* Allocating sub string for the maximum number of parenthesis */ - reg->sub_strings = calloc(max_prts_size + 1, sizeof(char *)); + reg->sub_strings = (char **) calloc(max_prts_size + 1, sizeof(char *)); if(reg->sub_strings == NULL) { reg->error = OS_REGEX_OUTOFMEMORY;