Merge branch 'develop' into firewall

This commit is contained in:
Markus Makela
2014-11-04 18:42:35 +02:00
7 changed files with 212 additions and 208 deletions

View File

@ -24,14 +24,21 @@ configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_BINARY_
set(CMAKE_C_FLAGS "-Wall -fPIC")
set(CMAKE_CXX_FLAGS "-Wall -fPIC")
set(DEBUG_FLAGS "-ggdb -pthread -pipe -Wformat -fstack-protector --param=ssp-buffer-size=4")
if((CMAKE_C_COMPILER_ID STREQUAL "GNU") AND (NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.2)))
message(STATUS "C Compiler supports: -Werror=format-security")
set(DEBUG_FLAGS "${DEBUG_FLAGS} -Werror=format-security")
endif()
if(BUILD_TYPE STREQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -pthread -pipe -DSS_DEBUG -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -pthread -pipe -DSS_DEBUG -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS} -DSS_DEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS} -DSS_DEBUG")
message(STATUS "Generating debugging symbols and enabling debugging code")
elseif(BUILD_TYPE STREQUAL DebugSymbols)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb -pthread -pipe -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -pthread -pipe -Wformat -Werror=format-security -fstack-protector --param=ssp-buffer-size=4")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS}")
message(STATUS "Generating debugging symbols")
elseif(BUILD_TYPE MATCHES Optimized)
if(NOT (DEFINED OLEVEL))
@ -59,7 +66,6 @@ if(GCOV)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lgcov")
endif()
subdirs(MYSQL_DIR_ALL ${MYSQL_DIR})
foreach(DIR ${MYSQL_DIR_ALL})
include_directories(${DIR})

View File

@ -1,3 +1,4 @@
#include <my_config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -7,7 +8,7 @@
#include <mysql.h>
static char* server_options[] = {
"SkySQL Gateway",
"MariaDB Corporation MaxScale",
"--datadir=./",
"--language=./",
"--skip-innodb",
@ -18,104 +19,60 @@ static char* server_options[] = {
const int num_elements = (sizeof(server_options) / sizeof(char *)) - 1;
static char* server_groups[] = {
"embedded",
"server",
"server",
NULL
"embedded",
"server",
"server",
NULL
};
int main(int argc, char** argv)
{
int fdin,fdout,i=0,fnamelen,fsz,lines = 0;
unsigned int psize;
GWBUF** qbuff;
char *qin, *outnm, *buffer, *tok;
unsigned int psize;
GWBUF* qbuff;
char *tok;
char readbuff[4092];
FILE* infile;
FILE* outfile;
if(argc != 3){
printf("Usage: canonizer <input file> <output file>\n");
return 1;
}
if(argc != 3){
printf("Usage: canonizer <input file> <output file>\n");
return 1;
}
if(mysql_library_init(num_elements, server_options, server_groups)){
printf("Embedded server init failed.\n");
return 1;
}
infile = fopen(argv[1],"rb");
outfile = fopen(argv[2],"wb");
if(infile == NULL || outfile == NULL){
printf("Opening files failed.\n");
return 1;
}
bool failed = mysql_library_init(num_elements, server_options, server_groups);
if(failed){
printf("Embedded server init failed.\n");
return 1;
}
fnamelen = strlen(argv[1]) + 16;
fdin = open(argv[1],O_RDONLY);
fsz = lseek(fdin,0,SEEK_END);
lseek(fdin,0,SEEK_SET);
if(!(buffer = malloc(sizeof(char)*fsz + 1))){
printf("Error: Failed to allocate memory.");
return 1;
}
read(fdin,buffer,fsz);
buffer[fsz] = '\0';
i = 0;
int bsz = 4,z=0;
qbuff = calloc(bsz,sizeof(GWBUF*));
tok = strtok(buffer,"\n");
while(tok){
if(i>=bsz){
GWBUF** tmp = calloc(bsz*2,sizeof(GWBUF*));
if(!tmp){
printf("Error: Failed to allocate memory.");
return 1;
}
for(z=0;z<bsz;z++){
tmp[z] = qbuff[z];
}
free(qbuff);
qbuff = tmp;
bsz *= 2;
}
if(strlen(tok) > 0){
qin = strdup(tok);
psize = strlen(qin);
qbuff[i] = gwbuf_alloc(psize + 6);
*(qbuff[i]->sbuf->data + 0) = (unsigned char)psize;
*(qbuff[i]->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff[i]->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff[i]->sbuf->data + 4) = 0x03;
memcpy(qbuff[i]->sbuf->data + 5,qin,psize);
*(qbuff[i]->sbuf->data + 5 + psize) = 0x00;
tok = strtok(NULL,"\n\0");
free(qin);
i++;
}
}
fdout = open(argv[2],O_TRUNC|O_CREAT|O_WRONLY,S_IRWXU|S_IXGRP|S_IXOTH);
for(i = 0;i<bsz;i++){
if(qbuff[i]){
parse_query(qbuff[i]);
tok = skygw_get_canonical(qbuff[i]);
write(fdout,tok,strlen(tok));
write(fdout,"\n",1);
gwbuf_free(qbuff[i]);
}
}
free(qbuff);
free(buffer);
close(fdin);
close(fdout);
return 0;
while(!feof(infile))
{
fgets(readbuff,4092,infile);
psize = strlen(readbuff);
qbuff = gwbuf_alloc(psize + 7);
*(qbuff->sbuf->data + 0) = (unsigned char)psize;
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03;
strcpy((char*)(qbuff->start + 5),readbuff);
parse_query(qbuff);
tok = skygw_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok);
free(tok);
gwbuf_free(qbuff);
}
fclose(infile);
fclose(outfile);
mysql_library_end();
return 0;
}

View File

@ -1,17 +1,18 @@
select md5("?") =?, sleep(?), rand(?)
select * from my1 where md5("?") =?
select md5("?") =?
select * from my1 where md5("?") =?
select sleep(?)
select * from tst where lname='?'
select ?,?,?,?,?,? from tst
select * from tst where fname like '?'
select * from tst where lname like '?' order by fname
insert into tst values ("?","?"),("?",?),("?","?")
drop table if exists tst
create table tst(fname varchar(30), lname varchar(30))
update tst set lname="?" where fname like '?' or lname like '?'
delete from tst where lname like '?' and fname like '?'
select ? from tst where fname='?' or lname like '?'
select ?,?,?,? from tst where name='?' or name='?' or name='?' or name='?'
select count(?),count(?),count(?),count(?),count (?),count(?) from tst
select md5("?") =?, sleep(?), rand(?);
select * from my1 where md5("?") =?;
select md5("?") =?;
select * from my1 where md5("?") =?;
select sleep(?);
select * from tst where lname='?';
select ?,?,?,?,?,? from tst;
select * from tst where fname like '?';
select * from tst where lname like '?' order by fname;
insert into tst values ("?","?"),("?",?),("?","?");
drop table if exists tst;
create table tst(fname varchar(30), lname varchar(30));
update tst set lname="?" where fname like '?' or lname like '?';
delete from tst where lname like '?' and fname like '?';
select ? from tst where fname='?' or lname like '?';
select ?,?,?,? from tst where name='?' or name='?' or name='?' or name='?';
select count(?),count(?),count(?),count(?),count (?),count(?) from tst;
select count(?),count(?),count(?),count(?),count (?),count(?) from tst;

View File

@ -1161,23 +1161,28 @@ dcb_close(DCB *dcb)
dcb,
STRDCBSTATE(dcb->state))));
}
if (rc == 0)
{
/**
* close protocol and router session
*/
if (dcb->func.close != NULL)
{
dcb->func.close(dcb);
}
dcb_call_callback(dcb, DCB_REASON_CLOSE);
if (dcb->state == DCB_STATE_NOPOLLING)
{
dcb_add_to_zombieslist(dcb);
}
}
}
ss_dassert(dcb->state == DCB_STATE_NOPOLLING ||
dcb->state == DCB_STATE_ZOMBIE);
/**
* close protocol and router session
*/
if (dcb->func.close != NULL)
{
dcb->func.close(dcb);
}
dcb_call_callback(dcb, DCB_REASON_CLOSE);
if (dcb->state == DCB_STATE_NOPOLLING)
{
dcb_add_to_zombieslist(dcb);
}
dcb->state == DCB_STATE_ZOMBIE);
}
/**

View File

@ -93,7 +93,7 @@ unsigned char mask;
{
bitmask->bits = realloc(bitmask->bits,
(bitmask->length + BIT_LENGTH_INC) / 8);
memset(bitmask + (bitmask->length / 8), 0,
memset(bitmask->bits + (bitmask->length / 8), 0,
BIT_LENGTH_INC / 8);
bitmask->length += (BIT_LENGTH_INC / 8);
}

View File

@ -292,7 +292,8 @@ poll_remove_dcb(DCB *dcb)
CHK_DCB(dcb);
/*< It is possible that dcb has already been removed from the set */
if (dcb->state != DCB_STATE_POLLING) {
if (dcb->state != DCB_STATE_POLLING)
{
if (dcb->state == DCB_STATE_NOPOLLING ||
dcb->state == DCB_STATE_ZOMBIE)
{
@ -300,7 +301,6 @@ poll_remove_dcb(DCB *dcb)
}
goto return_rc;
}
/*<
* Set state to NOPOLLING and remove dcb from poll set.
*/

View File

@ -267,83 +267,104 @@ int clientReply(void* ins, void* session, GWBUF* queue)
return 1;
}
/**
* Read a string from a file descriptor to a block of memory
* @param fd File descriptor to read from, assumed to be open
* @param buff Buffer to write to
* @param size Size of the buffer
* @return Number of bytes read
*/
int fdgets(int fd, char* buff, int size)
{
int i = 0;
while(i < size - 1 && read(fd,&buff[i],1))
{
if(buff[i] == '\n' || buff[i] == '\0')
{
break;
}
i++;
}
buff[i] = '\0';
return i;
}
/**
* Loads a query from a file
*@return 0 if successful, 1 if an error occurred
*/
int load_query()
{
char** query_list;
char* buff;
char rc;
int i, qcount = 0, qbuff_sz = 10, buff_sz = 2048;
char** query_list = NULL;
char* buffer = NULL;
int i, qcount = 0, qbuff_sz = 10, rval = 0;
int offset = 0;
unsigned int qlen = 0;
if((buff = calloc(buff_sz,sizeof(char))) == NULL ||
(query_list = calloc(qbuff_sz,sizeof(char*))) == NULL){
if((buffer = malloc(4092*sizeof(char))) == NULL){
printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
return 1;
}
while(read(instance.infile,&rc,1)){
if(rc != '\n' && rc != '\0'){
if(offset >= buff_sz){
char* tmp = malloc(sizeof(char)*2*buff_sz);
if(tmp){
memcpy(tmp,buff,buff_sz);
free(buff);
buff = tmp;
buff_sz *= 2;
}else{
printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
free(buff);
return 1;
}
}
buff[offset++] = rc;
}else{
if(qcount >= qbuff_sz){
char** tmpcl = malloc(sizeof(char*) * (qcount * 2 + 1));
if(!tmpcl){
printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
return 1;
}
for(i = 0;i < qbuff_sz;i++){
tmpcl[i] = query_list[i];
}
free(query_list);
query_list = tmpcl;
qbuff_sz = qcount * 2 + 1;
}
query_list[qcount] = malloc(sizeof(char)*(offset + 1));
memcpy(query_list[qcount],buff,offset);
query_list[qcount][offset] = '\0';
offset = 0;
qcount++;
}
if((query_list = calloc(qbuff_sz,sizeof(char*))) == NULL){
printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
rval = 1;
goto retblock;
}
while((offset = fdgets(instance.infile,buffer,4092))){
if(qbuff_sz <= qcount){
char** tmpbuff = realloc(query_list,sizeof(char*)*qbuff_sz*2);
if(tmpbuff == NULL){
printf("Error: cannot allocate enough memory.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory.\n");
rval = 1;
goto retblock;
}
query_list = tmpbuff;
qbuff_sz *= 2;
}
query_list[qcount] = calloc((offset + 1),sizeof(char));
strcpy(query_list[qcount],buffer);
offset = 0;
qcount++;
}
/**TODO check what messes up the first querystring*/
GWBUF** tmpbff = malloc(sizeof(GWBUF*)*(qcount + 1));
if(tmpbff){
for(i = 0;i<qcount;i++){
tmpbff[i] = gwbuf_alloc(strnlen(query_list[i],buff_sz) + 6);
tmpbff[i] = gwbuf_alloc(strlen(query_list[i]) + 6);
if(tmpbff[i] == NULL)
{
printf("Error: cannot allocate a new buffer.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate a new buffer.\n");
int x;
for(x = 0;x<i;x++)
{
gwbuf_free(tmpbff[x]);
}
free(tmpbff);
rval = 1;
goto retblock;
}
gwbuf_set_type(tmpbff[i],GWBUF_TYPE_MYSQL);
memcpy(tmpbff[i]->sbuf->data + 5,query_list[i],strnlen(query_list[i],buff_sz));
qlen = strnlen(query_list[i],buff_sz);
strcpy((char*)(tmpbff[i]->start + 5),query_list[i]);
qlen = strlen(query_list[i]) + 1;
tmpbff[i]->sbuf->data[0] = qlen;
tmpbff[i]->sbuf->data[1] = (qlen << 8);
tmpbff[i]->sbuf->data[2] = (qlen << 16);
@ -357,14 +378,26 @@ int load_query()
printf("Error: cannot allocate enough memory for buffers.\n");
skygw_log_write(LOGFILE_ERROR,"Error: cannot allocate enough memory for buffers.\n");
free_buffers();
return 1;
rval = 1;
goto retblock;
}
if(qcount < 1){
return 1;
rval = 1;
goto retblock;
}
instance.buffer_count = qcount;
return 0;
retblock:
for(i = 0;i<qcount;i++)
{
free(query_list[i]);
}
free(query_list);
free(buffer);
return rval;
}
@ -572,7 +605,7 @@ int load_config( char* fname)
int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
{
FILTER_PARAMETER** fparams;
FILTER_PARAMETER** fparams = NULL;
int i, paramc = -1;
if(cnf == NULL){
@ -640,7 +673,7 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
int sess_err = 0;
if(fc && fc->instance){
if(cnf && fc && fc->instance){
fc->filter = (FILTER*)fc->instance->createInstance(NULL,fparams);
@ -713,15 +746,14 @@ int load_filter(FILTERCHAIN* fc, CONFIG* cnf)
}
if(cnf){
int x;
for(x = 0;x<paramc;x++){
free(fparams[x]->name);
free(fparams[x]->value);
}
free(fparams);
int x;
for(x = 0;x<paramc;x++){
free(fparams[x]->name);
free(fparams[x]->value);
}
free(fparams);
return sess_err ? 0 : 1;
}
@ -893,7 +925,7 @@ GWBUF* gen_packet(PACKET pkt)
int process_opts(int argc, char** argv)
{
int fd = open_file("harness.cnf",1), buffsize = 1024;
int rd,fsize;
int rd,fsize,rdsz;
char *buff = calloc(buffsize,sizeof(char)), *tok = NULL;
/**Parse 'harness.cnf' file*/
@ -901,7 +933,8 @@ int process_opts(int argc, char** argv)
lseek(fd,0,SEEK_SET);
instance.thrcount = 1;
instance.session_count = 1;
read(fd,buff,fsize);
rdsz = read(fd,buff,fsize);
buff[rdsz] = '\0';
tok = strtok(buff,"=");
while(tok){
if(!strcmp(tok,"threads")){
@ -992,6 +1025,8 @@ int process_opts(int argc, char** argv)
}else{
instance.running = 0;
}
free(conf_name);
close(fd);
return 0;
}