From 9d8de1ec122658db71e2c630a22cfe4d2eaf687f Mon Sep 17 00:00:00 2001 From: Jeff Wasty Date: Tue, 26 Mar 2024 15:09:06 -0700 Subject: [PATCH 1/3] Null check for getCounter --- src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java | 4 ++++ .../java/com/microsoft/sqlserver/jdbc/SQLServerResource.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index afde39106..79185e555 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -6916,6 +6916,10 @@ final boolean readPacket() throws SQLServerException { // if messageType is RPC or QUERY, then increment Counter's state if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC() && null != command) { + if (null == command.getCounter()) { + throw new SQLServerException(this, SQLServerException.getErrString("R_counterIsNull"), null, 0, + false); + } command.getCounter().increaseCounter(packetLength); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 6cd502b72..68950fca9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -535,7 +535,7 @@ protected Object[][] getContents() { {"R_crCommandCannotTimeOut", "Request failed to time out and SQLServerConnection does not exist"}, {"R_InvalidIPAddressPreference", "IP address preference {0} is not valid."}, {"R_UnableLoadAuthDll", "Unable to load authentication DLL {0}"}, - {"R_illegalArgumentTrustManager", "Interal error. Peer certificate chain or key exchange algorithem can not be null or empty."}, + {"R_illegalArgumentTrustManager", "Internal error. Peer certificate chain or key exchange algorithm can not be null or empty."}, {"R_serverCertExpired", "Server Certificate has expired: {0}: {1}"}, {"R_serverCertNotYetValid", "Server Certificate is not yet valid: {0}: {1}"}, {"R_serverCertError", "Error validating Server Certificate: {0}: \n{1}:\n{2}."}, @@ -547,6 +547,7 @@ protected Object[][] getContents() { {"R_InvalidSqlQuery", "Invalid SQL Query: {0}"}, {"R_InvalidScale", "Scale of input value is larger than the maximum allowed by SQL Server."}, {"R_colCountNotMatchColTypeCount", "Number of provided columns {0} does not match the column data types definition {1}."}, + {"R_counterIsNull", "Unable to increase state of counter for the current command, as the counter is null."}, }; } // @formatter:on From ee65903ef6b3c3cb90cc4e0fa3f7db94a1465651 Mon Sep 17 00:00:00 2001 From: Jeff Wasty Date: Tue, 2 Apr 2024 10:19:53 -0700 Subject: [PATCH 2/3] Review fixes --- src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java | 9 +++++++-- .../com/microsoft/sqlserver/jdbc/SQLServerResource.java | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 79185e555..9762883c2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -6916,9 +6916,14 @@ final boolean readPacket() throws SQLServerException { // if messageType is RPC or QUERY, then increment Counter's state if (tdsChannel.getWriter().checkIfTdsMessageTypeIsBatchOrRPC() && null != command) { + if (logger.isLoggable(Level.FINER)) { + logger.warning(toString() + ": increasing state of counter for TDS Command: " + command.toString()); + } + if (null == command.getCounter()) { - throw new SQLServerException(this, SQLServerException.getErrString("R_counterIsNull"), null, 0, - false); + MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue")); + Object[] msgArgs1 = {"TDS command counter"}; + throw new SQLServerException(form.format(msgArgs1), null); } command.getCounter().increaseCounter(packetLength); } diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 68950fca9..3defa367c 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -546,8 +546,7 @@ protected Object[][] getContents() { {"R_AmbiguousRowUpdate", "Failed to execute updateRow(). The update is attempting an ambiguous update on tables \"{0}\" and \"{1}\". Ensure all columns being updated prior to the updateRow() call belong to the same table."}, {"R_InvalidSqlQuery", "Invalid SQL Query: {0}"}, {"R_InvalidScale", "Scale of input value is larger than the maximum allowed by SQL Server."}, - {"R_colCountNotMatchColTypeCount", "Number of provided columns {0} does not match the column data types definition {1}."}, - {"R_counterIsNull", "Unable to increase state of counter for the current command, as the counter is null."}, + {"R_colCountNotMatchColTypeCount", "Number of provided columns {0} does not match the column data types definition {1}."} }; } // @formatter:on From 5b94ee57aa3f0ad04aadbabfa5fd9ded5afa475f Mon Sep 17 00:00:00 2001 From: Jeff Wasty Date: Tue, 2 Apr 2024 10:20:42 -0700 Subject: [PATCH 3/3] Added trailing comma to reduce code diff --- .../java/com/microsoft/sqlserver/jdbc/SQLServerResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java index 3defa367c..28a1b219a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerResource.java @@ -546,7 +546,7 @@ protected Object[][] getContents() { {"R_AmbiguousRowUpdate", "Failed to execute updateRow(). The update is attempting an ambiguous update on tables \"{0}\" and \"{1}\". Ensure all columns being updated prior to the updateRow() call belong to the same table."}, {"R_InvalidSqlQuery", "Invalid SQL Query: {0}"}, {"R_InvalidScale", "Scale of input value is larger than the maximum allowed by SQL Server."}, - {"R_colCountNotMatchColTypeCount", "Number of provided columns {0} does not match the column data types definition {1}."} + {"R_colCountNotMatchColTypeCount", "Number of provided columns {0} does not match the column data types definition {1}."}, }; } // @formatter:on