Skip to content

Commit

Permalink
Fix for Bug#32122553, EXTRA BYTE IN COM_STMT_EXECUTE.
Browse files Browse the repository at this point in the history
  • Loading branch information
fjssilva committed Feb 10, 2021
1 parent d11cb2f commit 3b43b13
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.24

- Fix for Bug#32122553, EXTRA BYTE IN COM_STMT_EXECUTE.

- Fix for Bug#101558 (32141210), NULLPOINTEREXCEPTION WHEN EXECUTING INVALID QUERY WITH USEUSAGEADVISOR ENABLED.

- Fix for Bug#102076 (32329915), CONTRIBUTION: MYSQL JDBC DRIVER RESULTSET.GETLONG() THROWS NUMBEROUTOFRANGE.
Expand Down
71 changes: 37 additions & 34 deletions src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -269,49 +269,52 @@ public NativePacketPayload prepareExecutePacket() {

packet.writeInteger(IntegerDataType.INT4, 1); // placeholder for parameter iterations

/* Reserve place for null-marker bytes */
int nullCount = (this.parameterCount + 7) / 8;
if (this.parameterCount > 0) {
/* Reserve place for null-marker bytes */
int nullCount = (this.parameterCount + 7) / 8;

int nullBitsPosition = packet.getPosition();
int nullBitsPosition = packet.getPosition();

for (int i = 0; i < nullCount; i++) {
packet.writeInteger(IntegerDataType.INT1, 0);
}
for (int i = 0; i < nullCount; i++) {
packet.writeInteger(IntegerDataType.INT1, 0);
}

byte[] nullBitsBuffer = new byte[nullCount];
byte[] nullBitsBuffer = new byte[nullCount];

/* In case if buffers (type) altered, indicate to server */
packet.writeInteger(IntegerDataType.INT1, this.queryBindings.getSendTypesToServer().get() ? (byte) 1 : (byte) 0);
/* In case if buffers (type) altered, indicate to server */
packet.writeInteger(IntegerDataType.INT1, this.queryBindings.getSendTypesToServer().get() ? (byte) 1 : (byte) 0);

if (this.queryBindings.getSendTypesToServer().get()) {
/*
* Store types of parameters in the first package that is sent to the server.
*/
for (int i = 0; i < this.parameterCount; i++) {
packet.writeInteger(IntegerDataType.INT2, parameterBindings[i].bufferType);
if (this.queryBindings.getSendTypesToServer().get()) {
/*
* Store types of parameters in the first package that is sent to the server.
*/
for (int i = 0; i < this.parameterCount; i++) {
packet.writeInteger(IntegerDataType.INT2, parameterBindings[i].bufferType);
}
}
}

//
// store the parameter values
//
for (int i = 0; i < this.parameterCount; i++) {
if (!parameterBindings[i].isStream()) {
if (!parameterBindings[i].isNull()) {
parameterBindings[i].storeBinding(packet, this.queryBindings.isLoadDataQuery(), this.charEncoding, this.session.getExceptionInterceptor());
} else {
nullBitsBuffer[i / 8] |= (1 << (i & 7));
//
// store the parameter values
//
for (int i = 0; i < this.parameterCount; i++) {
if (!parameterBindings[i].isStream()) {
if (!parameterBindings[i].isNull()) {
parameterBindings[i].storeBinding(packet, this.queryBindings.isLoadDataQuery(), this.charEncoding,
this.session.getExceptionInterceptor());
} else {
nullBitsBuffer[i / 8] |= (1 << (i & 7));
}
}
}
}

//
// Go back and write the NULL flags to the beginning of the packet
//
int endPosition = packet.getPosition();
packet.setPosition(nullBitsPosition);
packet.writeBytes(StringLengthDataType.STRING_FIXED, nullBitsBuffer);
packet.setPosition(endPosition);
//
// Go back and write the NULL flags to the beginning of the packet
//
int endPosition = packet.getPosition();
packet.setPosition(nullBitsPosition);
packet.writeBytes(StringLengthDataType.STRING_FIXED, nullBitsBuffer);
packet.setPosition(endPosition);
}

return packet;
}
Expand Down

0 comments on commit 3b43b13

Please sign in to comment.