From 3b43b13aa9e0d4cc6272ea974c58d4f44c458d85 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Thu, 28 Jan 2021 15:53:53 +0000 Subject: [PATCH] Fix for Bug#32122553, EXTRA BYTE IN COM_STMT_EXECUTE. --- CHANGES | 2 + .../com/mysql/cj/ServerPreparedQuery.java | 71 ++++++++++--------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index 6a995605a..09dff4309 100644 --- a/CHANGES +++ b/CHANGES @@ -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. diff --git a/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java b/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java index 75d369364..768e99b9a 100644 --- a/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java +++ b/src/main/core-impl/java/com/mysql/cj/ServerPreparedQuery.java @@ -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 @@ -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; }