Skip to content

Commit

Permalink
Merge pull request #255 from v-xiangs/set-network-timeout-permission
Browse files Browse the repository at this point in the history
setNetworkTimeout checks for SQLPermission before proceeding
  • Loading branch information
Suraiya Hameed authored Apr 26, 2017
2 parents eb801aa + 46c9f1c commit 616472b
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ ServerPortPlaceHolder getRoutingInfo() {
}

// Permission targets
// currently only callAbort is implemented
private static final String callAbortPerm = "callAbort";

private static final String SET_NETWORK_TIMEOUT_PERM = "setNetworkTimeout";

private boolean sendStringParametersAsUnicode = SQLServerDriverBooleanProperty.SEND_STRING_PARAMETERS_AS_UNICODE.getDefaultValue(); // see
// connection
Expand Down Expand Up @@ -4689,6 +4690,20 @@ public void setNetworkTimeout(Executor executor,
}

checkClosed();

// check for setNetworkTimeout permission
SecurityManager secMgr = System.getSecurityManager();
if (secMgr != null) {
try {
SQLPermission perm = new SQLPermission(SET_NETWORK_TIMEOUT_PERM);
secMgr.checkPermission(perm);
}
catch (SecurityException ex) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
Object[] msgArgs = {SET_NETWORK_TIMEOUT_PERM};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
}
}

try {
tdsChannel.setNetworkTimeout(timeout);
Expand Down

0 comments on commit 616472b

Please sign in to comment.