Skip to content

Commit

Permalink
Ensure that the scramble sent during handshake has always positive char
Browse files Browse the repository at this point in the history
#1636

This seems a problem only with MySQL Connector/J 8.0 , but it is possible that other drivers could be affected
  • Loading branch information
renecannao committed Aug 8, 2018
1 parent 6c27216 commit 3551130
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/MySQL_Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ void proxy_create_random_string(char *to, uint length, struct rand_struct *rand_
}
} else {
for (i=0; i<length ; i++) {
if (*to < 0) {
*to += 128;
} else {
if (*to == 0) {
*to = 'a';
}
}
to++;
}
}
Expand Down Expand Up @@ -1061,11 +1068,12 @@ bool MySQL_Protocol::generate_pkt_initial_handshake(bool send, void **ptr, unsig
//#endif

int i;
for (i=0;i<8;i++) {
if ((*myds)->myconn->scramble_buff[i]==0) {
(*myds)->myconn->scramble_buff[i]='a';
}
}

// for (i=0;i<8;i++) {
// if ((*myds)->myconn->scramble_buff[i]==0) {
// (*myds)->myconn->scramble_buff[i]='a';
// }
// }

memcpy(_ptr+l, (*myds)->myconn->scramble_buff+0, 8); l+=8;
_ptr[l]=0x00; l+=1; //0x00
Expand Down Expand Up @@ -1093,11 +1101,11 @@ bool MySQL_Protocol::generate_pkt_initial_handshake(bool send, void **ptr, unsig
//#endif
//create_random_string(scramble_buf+8,12,&rand_st);

for (i=8;i<20;i++) {
if ((*myds)->myconn->scramble_buff[i]==0) {
(*myds)->myconn->scramble_buff[i]='a';
}
}
// for (i=8;i<20;i++) {
// if ((*myds)->myconn->scramble_buff[i]==0) {
// (*myds)->myconn->scramble_buff[i]='a';
// }
// }

memcpy(_ptr+l, (*myds)->myconn->scramble_buff+8, 12); l+=12;
l+=1; //0x00
Expand Down

0 comments on commit 3551130

Please sign in to comment.