Replace qc_get_affected_fields with qc_get_field_info

qc_get_affected_fields that returned the fields as one string with
fields interspared with spaces, will be removed.
This commit is contained in:
Johan Wikman
2016-11-07 11:02:49 +02:00
parent 568153efb9
commit 9fa1a0cfec

View File

@ -1701,13 +1701,12 @@ bool rule_matches(FW_INSTANCE* my_instance,
RULELIST *rulelist, RULELIST *rulelist,
char* query) char* query)
{ {
char *ptr, *where, *msg = NULL; char *ptr, *msg = NULL;
char emsg[512]; char emsg[512];
unsigned char* memptr = (unsigned char*) queue->start; unsigned char* memptr = (unsigned char*) queue->start;
bool is_sql, is_real, matches; bool is_sql, is_real, matches;
qc_query_op_t optype = QUERY_OP_UNDEFINED; qc_query_op_t optype = QUERY_OP_UNDEFINED;
STRLINK* strln = NULL;
QUERYSPEED* queryspeed = NULL; QUERYSPEED* queryspeed = NULL;
QUERYSPEED* rule_qs = NULL; QUERYSPEED* rule_qs = NULL;
time_t time_now; time_t time_now;
@ -1745,7 +1744,7 @@ bool rule_matches(FW_INSTANCE* my_instance,
case QUERY_OP_UPDATE: case QUERY_OP_UPDATE:
case QUERY_OP_INSERT: case QUERY_OP_INSERT:
case QUERY_OP_DELETE: case QUERY_OP_DELETE:
// In these cases, we have to be able to trust what qc_get_affected_fields // In these cases, we have to be able to trust what qc_get_field_info
// returns. Unless the query was parsed completely, we cannot do that. // returns. Unless the query was parsed completely, we cannot do that.
msg = create_parse_error(my_instance, "parsed completely", query, &matches); msg = create_parse_error(my_instance, "parsed completely", query, &matches);
goto queryresolved; goto queryresolved;
@ -1817,14 +1816,15 @@ bool rule_matches(FW_INSTANCE* my_instance,
case RT_COLUMN: case RT_COLUMN:
if (is_sql && is_real) if (is_sql && is_real)
{ {
where = qc_get_affected_fields(queue); const QC_FIELD_INFO* infos;
if (where != NULL) size_t n_infos;
qc_get_field_info(queue, &infos, &n_infos);
for (size_t i = 0; i < n_infos; ++i)
{ {
char* saveptr; const char* tok = infos[i].column;
char* tok = strtok_r(where, " ", &saveptr);
while (tok) STRLINK* strln = (STRLINK*) rulelist->rule->data;
{
strln = (STRLINK*) rulelist->rule->data;
while (strln) while (strln)
{ {
if (strcasecmp(tok, strln->value) == 0) if (strcasecmp(tok, strln->value) == 0)
@ -1835,14 +1835,10 @@ bool rule_matches(FW_INSTANCE* my_instance,
MXS_INFO("dbfwfilter: rule '%s': query targets forbidden column: %s", MXS_INFO("dbfwfilter: rule '%s': query targets forbidden column: %s",
rulelist->rule->name, strln->value); rulelist->rule->name, strln->value);
msg = MXS_STRDUP_A(emsg); msg = MXS_STRDUP_A(emsg);
MXS_FREE(where);
goto queryresolved; goto queryresolved;
} }
strln = strln->next; strln = strln->next;
} }
tok = strtok_r(NULL, ",", &saveptr);
}
MXS_FREE(where);
} }
} }
break; break;
@ -1850,23 +1846,22 @@ bool rule_matches(FW_INSTANCE* my_instance,
case RT_WILDCARD: case RT_WILDCARD:
if (is_sql && is_real) if (is_sql && is_real)
{ {
char * strptr; const QC_FIELD_INFO* infos;
where = qc_get_affected_fields(queue); size_t n_infos;
qc_get_field_info(queue, &infos, &n_infos);
if (where != NULL) for (size_t i = 0; i < n_infos; ++i)
{ {
strptr = where; const char* column = infos[i].column;
if (strchr(strptr, '*')) if (strcmp(column, "*") == 0)
{ {
matches = true; matches = true;
msg = MXS_STRDUP_A("Usage of wildcard denied."); msg = MXS_STRDUP_A("Usage of wildcard denied.");
MXS_INFO("dbfwfilter: rule '%s': query contains a wildcard.", MXS_INFO("dbfwfilter: rule '%s': query contains a wildcard.",
rulelist->rule->name); rulelist->rule->name);
MXS_FREE(where);
goto queryresolved; goto queryresolved;
} }
MXS_FREE(where);
} }
} }
break; break;