Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid SQL Server JDBC driver to load ANTLR parsers #27343

Merged
merged 1 commit into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

import com.microsoft.sqlserver.jdbc.SQLServerException;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
import com.oracle.svm.core.annotate.AlwaysInline;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

@@ -60,6 +62,50 @@ static KeyManager[] getKeyManagerFromFile(String certPath, String keyPath, Strin
}
}

@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerLexer")
@Delete //Deleting this one explicitly, so to help with maintenance with the substitutions of SQLServerFMTQuery
final class SQLServerLexerRemove {

}

/**
* This will make sure the ANTLR4 Lexer included in the driver is not reachable; this was mostly
* prevented by not allowing to explicitly set the useFmtOnly connection property, but this code
* path would also get activated on very old SQL Server versions being detected on a connection.
* Since that's not a constant that the compiler can rely on, we need one more substitution.
*/
@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerFMTQuery")
final class SQLServerFMTQuery {

@Substitute
SQLServerFMTQuery(String userSql) throws SQLServerException {
throw new IllegalStateException("It is not supported to connect to SQL Server versions older than 2012");
}

}

/**
* This substitution is not strictly necessary, but it helps by providing a better error message to our users.
*/
@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement")
final class DisableFMTRemove {

@Substitute
@AlwaysInline("We need this to be constant folded")
public final boolean getUseFmtOnly() throws SQLServerException {
return false;//Important for this to be disabled via a constant
}

@Substitute
public final void setUseFmtOnly(boolean useFmtOnly) throws SQLServerException {
if (useFmtOnly) {
throw new IllegalStateException(
"It is not possible to enable the useFmtOnly option on Quarkus: this option is only useful on SQL Server version 2008 (which is not supported) and introduces several other problems.");
}
}

}

class SQLServerJDBCSubstitutions {

}