Added more error log output and fixed memory leaks.
This commit is contained in:
@ -588,7 +588,7 @@ RULE* find_rule(char* tok, FW_INSTANCE* instance)
|
|||||||
}
|
}
|
||||||
rlist = rlist->next;
|
rlist = rlist->next;
|
||||||
}
|
}
|
||||||
skygw_log_write(LOGFILE_ERROR, "fwfilter: Rule not found: %s",tok);
|
skygw_log_write(LOGFILE_ERROR, "Error : Rule not found: %s",tok);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,6 +602,10 @@ void add_users(char* rule, FW_INSTANCE* instance)
|
|||||||
assert(rule != NULL && instance != NULL);
|
assert(rule != NULL && instance != NULL);
|
||||||
|
|
||||||
STRLINK* link = calloc(1,sizeof(STRLINK));
|
STRLINK* link = calloc(1,sizeof(STRLINK));
|
||||||
|
if(link == NULL){
|
||||||
|
skygw_log_write(LOGFILE_ERROR,"Error : Memory allocation failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
link->next = instance->userstrings;
|
link->next = instance->userstrings;
|
||||||
link->value = strdup(rule);
|
link->value = strdup(rule);
|
||||||
instance->userstrings = link;
|
instance->userstrings = link;
|
||||||
@ -838,20 +842,21 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
|
|||||||
regex_t *re;
|
regex_t *re;
|
||||||
char* start, *str;
|
char* start, *str;
|
||||||
tok = strtok(NULL," ");
|
tok = strtok(NULL," ");
|
||||||
|
char delim = '\'';
|
||||||
while(*tok == '\'' || *tok == '"'){
|
while(*tok == '\'' || *tok == '"'){
|
||||||
|
delim = *tok;
|
||||||
tok++;
|
tok++;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = tok;
|
start = tok;
|
||||||
|
|
||||||
while(isspace(*tok) || *tok == '\'' || *tok == '"'){
|
while(isspace(*tok) || *tok == delim){
|
||||||
tok++;
|
tok++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
|
|
||||||
if((*tok == '\'' || *tok == '"') && !escaped){
|
if((*tok == delim) && !escaped){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
escaped = (*tok == '\\');
|
escaped = (*tok == '\\');
|
||||||
@ -896,11 +901,23 @@ void parse_rule(char* rule, FW_INSTANCE* instance)
|
|||||||
spinlock_release(instance->lock);
|
spinlock_release(instance->lock);
|
||||||
|
|
||||||
tok = strtok(NULL," ");
|
tok = strtok(NULL," ");
|
||||||
|
if(tok == NULL){
|
||||||
|
free(qs);
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
qs->limit = atoi(tok);
|
qs->limit = atoi(tok);
|
||||||
|
|
||||||
tok = strtok(NULL," ");
|
tok = strtok(NULL," ");
|
||||||
|
if(tok == NULL){
|
||||||
|
free(qs);
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
qs->period = atof(tok);
|
qs->period = atof(tok);
|
||||||
tok = strtok(NULL," ");
|
tok = strtok(NULL," ");
|
||||||
|
if(tok == NULL){
|
||||||
|
free(qs);
|
||||||
|
goto retblock;
|
||||||
|
}
|
||||||
qs->cooldown = atof(tok);
|
qs->cooldown = atof(tok);
|
||||||
ruledef->type = RT_THROTTLE;
|
ruledef->type = RT_THROTTLE;
|
||||||
ruledef->data = (void*)qs;
|
ruledef->data = (void*)qs;
|
||||||
@ -958,7 +975,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
|
|
||||||
spinlock_init(my_instance->lock);
|
spinlock_init(my_instance->lock);
|
||||||
|
|
||||||
if((ht = hashtable_alloc(7, hashkeyfun, hashcmpfun)) == NULL){
|
if((ht = hashtable_alloc(100, hashkeyfun, hashcmpfun)) == NULL){
|
||||||
skygw_log_write(LOGFILE_ERROR, "Unable to allocate hashtable.");
|
skygw_log_write(LOGFILE_ERROR, "Unable to allocate hashtable.");
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -979,15 +996,19 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(filename == NULL)
|
if(filename == NULL)
|
||||||
{
|
{
|
||||||
skygw_log_write(LOGFILE_ERROR, "Unable to find rule file for firewall filter.");
|
skygw_log_write(LOGFILE_ERROR, "Unable to find rule file for firewall filter. Please provide the path with"
|
||||||
|
" rules=<path to file>");
|
||||||
|
hashtable_free(my_instance->htable);
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((file = fopen(filename,"rb")) == NULL ){
|
if((file = fopen(filename,"rb")) == NULL ){
|
||||||
skygw_log_write(LOGFILE_ERROR, "Error while opening rule file for firewall filter.");
|
skygw_log_write(LOGFILE_ERROR, "Error while opening rule file for firewall filter.");
|
||||||
|
hashtable_free(my_instance->htable);
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
free(filename);
|
free(filename);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1002,6 +1023,7 @@ createInstance(char **options, FILTER_PARAMETER **params)
|
|||||||
if(ferror(file)){
|
if(ferror(file)){
|
||||||
skygw_log_write(LOGFILE_ERROR, "Error while reading rule file for firewall filter.");
|
skygw_log_write(LOGFILE_ERROR, "Error while reading rule file for firewall filter.");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
hashtable_free(my_instance->htable);
|
||||||
free(my_instance);
|
free(my_instance);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user