From aaa727bcc299c8ef6447e581f539e12effe26502 Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Sun, 2 Nov 2014 22:11:28 +0200 Subject: [PATCH] Fix to bug #605, http://bugs.mariadb.com/show_bug.cgi?id=605 String buffer allocation didn't allocate space for terminating char. It also assumed that character size may vary but the rest of the code didn't support multi-byte characters so I changed it consistently assume single-byte characters. --- .../test/canonical_tests/canonizer.c | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/query_classifier/test/canonical_tests/canonizer.c b/query_classifier/test/canonical_tests/canonizer.c index bffe9c1b9..dd200d1f2 100644 --- a/query_classifier/test/canonical_tests/canonizer.c +++ b/query_classifier/test/canonical_tests/canonizer.c @@ -28,17 +28,25 @@ static char* server_groups[] = { 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; + int fdin; + int fdout; + int fnamelen; + int fsz; + int lines = 0; + int i; + int bsz = 4; + int z=0; + unsigned int psize; + GWBUF** qbuff; + char *qin; + char *outnm; + char *buffer; + char *tok; if(argc != 3){ printf("Usage: canonizer \n"); return 1; } - - bool failed = mysql_library_init(num_elements, server_options, server_groups); @@ -52,19 +60,16 @@ int main(int argc, char** argv) fsz = lseek(fdin,0,SEEK_END); lseek(fdin,0,SEEK_SET); - if(!(buffer = malloc(sizeof(char)*fsz))){ + if (!(buffer = calloc(1, fsz+1))) + { printf("Error: Failed to allocate memory."); return 1; } - read(fdin,buffer,fsz); - - - i = 0; - int bsz = 4,z=0; qbuff = calloc(bsz,sizeof(GWBUF*)); tok = strtok(buffer,"\n"); + i = 0; while(tok){