This is an automated email from the ASF dual-hosted git repository.
terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6de93fe0a09 Ignore the unused operation field and the sign of protocol
versions in Firebird op_connect (#40208)
6de93fe0a09 is described below
commit 6de93fe0a09d0ef5cd7cc1bfea8e16413f1bbe22
Author: Maxim Igoshin <[email protected]>
AuthorDate: Sat Oct 17 05:00:10 2026 +0300
Ignore the unused operation field and the sign of protocol versions in
Firebird op_connect (#40208)
---
.../constant/protocol/FirebirdProtocol.java | 2 +-
.../packet/handshake/FirebirdConnectPacket.java | 3 +-
.../constant/protocol/FirebirdProtocolTest.java | 48 ++++++++++++++++++++++
.../handshake/FirebirdConnectPacketTest.java | 21 +++++++++-
4 files changed, 70 insertions(+), 4 deletions(-)
diff --git
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocol.java
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocol.java
index ddf5d7f1be5..b73e96999b9 100644
---
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocol.java
+++
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocol.java
@@ -38,7 +38,7 @@ public final class FirebirdProtocol {
private final int weight;
public FirebirdProtocol(final ByteBuf buffer) {
- version = FirebirdProtocolVersion.valueOf(buffer.readInt());
+ version = FirebirdProtocolVersion.valueOf(buffer.readInt() & 0xFFFF);
arch = FirebirdArchType.valueOf(buffer.readInt());
minType = buffer.readInt();
maxType = buffer.readInt();
diff --git
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacket.java
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacket.java
index dcdf5d40eed..3024cfcb4ff 100644
---
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacket.java
+++
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacket.java
@@ -56,7 +56,8 @@ public final class FirebirdConnectPacket extends
FirebirdPacket {
private final List<FirebirdProtocol> userProtocols = new ArrayList<>();
public FirebirdConnectPacket(final FirebirdPacketPayload payload) {
- opCode = FirebirdCommandPacketType.valueOf(payload.readInt4());
+ opCode = FirebirdCommandPacketType.CONNECT;
+ payload.skipReserved(4);
connectVersion = payload.readInt4();
archType = FirebirdArchType.valueOf(payload.readInt4());
database = payload.readString();
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocolTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocolTest.java
new file mode 100644
index 00000000000..1ce85d8376c
--- /dev/null
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/constant/protocol/FirebirdProtocolTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.database.protocol.firebird.constant.protocol;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import
org.apache.shardingsphere.database.protocol.firebird.constant.FirebirdArchType;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+class FirebirdProtocolTest {
+
+ @Test
+ void assertConstructor() {
+ FirebirdProtocol actual = new
FirebirdProtocol(createProtocolBuffer(FirebirdProtocolVersion.PROTOCOL_VERSION19.getCode()));
+ assertThat(actual.getVersion(),
is(FirebirdProtocolVersion.PROTOCOL_VERSION19));
+ assertThat(actual.getArch(), is(FirebirdArchType.ARCH_GENERIC));
+ assertThat(actual.getMinType(), is(0));
+ assertThat(actual.getMaxType(), is(5));
+ assertThat(actual.getWeight(), is(8));
+ }
+
+ @Test
+ void assertConstructorWithSignExtendedVersion() {
+ assertThat(new FirebirdProtocol(createProtocolBuffer((short)
FirebirdProtocolVersion.PROTOCOL_VERSION19.getCode())).getVersion(),
is(FirebirdProtocolVersion.PROTOCOL_VERSION19));
+ }
+
+ private ByteBuf createProtocolBuffer(final int version) {
+ return
Unpooled.buffer().writeInt(version).writeInt(FirebirdArchType.ARCH_GENERIC.getCode()).writeInt(0).writeInt(5).writeInt(8);
+ }
+}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
index 655fe18b0bc..349614d8316 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/handshake/FirebirdConnectPacketTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.database.protocol.firebird.packet.handshake;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import
org.apache.shardingsphere.database.protocol.firebird.constant.FirebirdArchType;
import
org.apache.shardingsphere.database.protocol.firebird.constant.FirebirdAuthenticationMethod;
import
org.apache.shardingsphere.database.protocol.firebird.constant.FirebirdUserDataType;
@@ -58,6 +59,22 @@ class FirebirdConnectPacketTest {
assertThat(actualProtocols.get(0).getVersion(),
is(FirebirdProtocolVersion.PROTOCOL_VERSION10));
}
+ @Test
+ void assertConstructorWithUnusedOperationOfFbclient() {
+ ByteBuf packet = Unpooled.buffer();
+
packet.writeInt(0x00030000).writeInt(3).writeInt(FirebirdArchType.ARCH_GENERIC.getCode());
+
packet.writeInt(6).writeBytes("foo_db".getBytes(StandardCharsets.US_ASCII)).writeZero(2);
+ packet.writeInt(1);
+
packet.writeInt(10).writeByte(FirebirdUserDataType.CNCT_LOGIN.getCode()).writeByte(8).writeBytes("foo_user".getBytes(StandardCharsets.US_ASCII)).writeZero(2);
+
packet.writeInt(FirebirdProtocolVersion.PROTOCOL_VERSION13.getCode()).writeInt(FirebirdArchType.ARCH_GENERIC.getCode()).writeInt(0).writeInt(5).writeInt(2);
+ FirebirdConnectPacket actual = new FirebirdConnectPacket(new
FirebirdPacketPayload(packet, StandardCharsets.UTF_8));
+ assertThat(actual.getOpCode(), is(FirebirdCommandPacketType.CONNECT));
+ assertThat(actual.getConnectVersion(), is(3));
+ assertThat(actual.getDatabase(), is("foo_db"));
+ assertThat(actual.getLogin(), is("foo_user"));
+ assertThat(actual.getUserProtocols().get(0).getVersion(),
is(FirebirdProtocolVersion.PROTOCOL_VERSION13));
+ }
+
@Test
void assertGetUsername() {
assertThat(createPacketWithSpecificData().getUsername(), is("user"));
@@ -94,7 +111,7 @@ class FirebirdConnectPacketTest {
}
private FirebirdConnectPacket createPacketWithSpecificData() {
-
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.CONNECT.getValue(),
1, FirebirdArchType.ARCH_GENERIC.getCode(), 1);
+ when(payload.readInt4()).thenReturn(1,
FirebirdArchType.ARCH_GENERIC.getCode(), 1);
when(payload.readString()).thenReturn("db");
ByteBuf userBuf = mock(ByteBuf.class);
when(userBuf.toString(StandardCharsets.UTF_8)).thenReturn("user");
@@ -121,7 +138,7 @@ class FirebirdConnectPacketTest {
}
private FirebirdConnectPacket createPacketWithoutSpecificData() {
-
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.CONNECT.getValue(),
1, FirebirdArchType.ARCH_GENERIC.getCode(), 0);
+ when(payload.readInt4()).thenReturn(1,
FirebirdArchType.ARCH_GENERIC.getCode(), 0);
when(payload.readString()).thenReturn("db");
ByteBuf hostBuf = mock(ByteBuf.class);
when(hostBuf.toString(StandardCharsets.UTF_8)).thenReturn("host");