Skip to content

Commit

Permalink
Check if TDSCommand counter is null before incrementing. (#2368)
Browse files Browse the repository at this point in the history
* Null check for getCounter

* Review fixes

* Added trailing comma to reduce code diff
  • Loading branch information
Jeffery-Wasty committed Apr 2, 2024
1 parent 7c78c48 commit bea8daa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6943,6 +6943,15 @@ 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()) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_NullValue"));
Object[] msgArgs1 = {"TDS command counter"};
throw new SQLServerException(form.format(msgArgs1), null);
}
command.getCounter().increaseCounter(packetLength);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}."},
Expand Down

0 comments on commit bea8daa

Please sign in to comment.