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.
This commit is contained in:
@ -28,18 +28,26 @@ static char* server_groups[] = {
|
|||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
|
||||||
int fdin,fdout,i=0,fnamelen,fsz,lines = 0;
|
int fdin;
|
||||||
unsigned int psize;
|
int fdout;
|
||||||
GWBUF** qbuff;
|
int fnamelen;
|
||||||
char *qin, *outnm, *buffer, *tok;
|
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){
|
if(argc != 3){
|
||||||
printf("Usage: canonizer <input file> <output file>\n");
|
printf("Usage: canonizer <input file> <output file>\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool failed = mysql_library_init(num_elements, server_options, server_groups);
|
bool failed = mysql_library_init(num_elements, server_options, server_groups);
|
||||||
|
|
||||||
if(failed){
|
if(failed){
|
||||||
@ -52,19 +60,16 @@ int main(int argc, char** argv)
|
|||||||
fsz = lseek(fdin,0,SEEK_END);
|
fsz = lseek(fdin,0,SEEK_END);
|
||||||
lseek(fdin,0,SEEK_SET);
|
lseek(fdin,0,SEEK_SET);
|
||||||
|
|
||||||
if(!(buffer = malloc(sizeof(char)*fsz))){
|
if (!(buffer = calloc(1, fsz+1)))
|
||||||
|
{
|
||||||
printf("Error: Failed to allocate memory.");
|
printf("Error: Failed to allocate memory.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
read(fdin,buffer,fsz);
|
read(fdin,buffer,fsz);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
int bsz = 4,z=0;
|
|
||||||
qbuff = calloc(bsz,sizeof(GWBUF*));
|
qbuff = calloc(bsz,sizeof(GWBUF*));
|
||||||
tok = strtok(buffer,"\n");
|
tok = strtok(buffer,"\n");
|
||||||
|
i = 0;
|
||||||
|
|
||||||
while(tok){
|
while(tok){
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user