[MXS-137] cannot get sql for queries with length >= 0x80 Created: 2015-05-12  Updated: 2015-05-13  Resolved: 2015-05-13

Status: Closed
Project: MariaDB MaxScale
Component/s: Core
Affects Version/s: None
Fix Version/s: 1.2.0

Type: Bug Priority: Major
Reporter: Yuval Hager Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None


 Description   

modutil_get_SQL uses signed char pointers to determine the query length. When the data is larger than 0x80, this is translated to a negative number, and then converted wrong to the unsigned int that is the length.

Here is an isolated test case that demonstrates the problem:

#include <stdio.h>
 
int main()
{
  /* simulates the data coming in. packet length should be 0x80 */
  char buf[4] = { 0x80, 0, 0, 0};
 
  char* ptr = buf;
  unsigned  int length;
  length = *ptr;
  printf("length when using signed char*: 0x%x\n", length);
 
  unsigned char* uptr = buf;
  length = *uptr;
  printf("length when using unsigned char*: 0x%x\n", length);
}

And the output is:

$ cc t.c
$ ./a.out 
length when using signed char*: 0xffffff80
length when using unsigned char*: 0x80

This then tries to allocate nunecessary 4G of memory.

I will send a PR.



 Comments   
Comment by Yuval Hager [ 2015-05-12 ]

https://github.com/mariadb-corporation/MaxScale/pull/82

Comment by markus makela [ 2015-05-13 ]

Merged into develop.

Comment by markus makela [ 2015-05-13 ]

Test case was added to the internal test suite and the fix was also manually confirmed.

Comment by Timofey Turenko [ 2015-05-13 ]

test is in Maxscale source server/core/test/testmodutil.c

Generated at Thu Feb 08 03:57:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.