Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-956] ArrayIndexOutOfBoundsException when alias length > 250
  • Loading branch information
rusher committed Apr 11, 2022
1 parent bb30bc3 commit e15fa25
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/main/java/org/mariadb/jdbc/Driver.java
Expand Up @@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.SocketAddress;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
Expand Down Expand Up @@ -57,9 +56,8 @@ public static Connection connect(Configuration configuration) throws SQLExceptio
break;

default:
ClientInstance<Configuration , HostAddress , ReentrantLock , Boolean ,Client>
clientInstance =
(configuration.transactionReplay()) ? ReplayClient::new : StandardClient::new;
ClientInstance<Configuration, HostAddress, ReentrantLock, Boolean, Client> clientInstance =
(configuration.transactionReplay()) ? ReplayClient::new : StandardClient::new;

if (configuration.addresses().isEmpty()) {
// unix socket / windows pipe
Expand All @@ -80,16 +78,13 @@ public static Connection connect(Configuration configuration) throws SQLExceptio
break;
}
return new Connection(configuration, lock, client);


}

@FunctionalInterface
public interface ClientInstance<T, U, V, W, R> {
R apply(T t, U u, V v, W w) throws SQLException;
}


/**
* Connect to the given connection string.
*
Expand Down
Expand Up @@ -108,8 +108,8 @@ public int readIntLengthEncodedNotNull() {
* @return current pos
*/
public int skipIdentifier() {
int type = buf[pos++] & 0xff;
pos += (type == 252) ? readUnsignedShort() : type;
int len = readLength();
pos += len;
return pos;
}

Expand Down
Expand Up @@ -1116,17 +1116,16 @@ public void createDatabaseIfNotExist() throws SQLException {
sharedConn.createStatement().execute("DROP DATABASE IF EXISTS `bla``f``l`");
}


@Test
public void loopHost() throws SQLException {
Assumptions.assumeTrue(
!"skysql".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv")));
!"skysql".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv")));

// ensure connecting without DB
String connStr =
String.format(
"jdbc:mariadb://wronghost,%s:%s/%s?user=%s&password=%s&%s",
hostname, port, database, user, password, defaultOther);
String.format(
"jdbc:mariadb://wronghost,%s:%s/%s?user=%s&password=%s&%s",
hostname, port, database, user, password, defaultOther);
try (Connection con = DriverManager.getConnection(connStr)) {
con.createStatement().executeQuery("SELECT 1");
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/mariadb/jdbc/integration/StatementTest.java
Expand Up @@ -26,12 +26,14 @@ public static void drop() throws SQLException {
stmt.execute("DROP TABLE IF EXISTS executeGenerated2");
stmt.execute("DROP TABLE IF EXISTS testAffectedRow");
stmt.execute("DROP TABLE IF EXISTS bigIntId");
stmt.execute("DROP TABLE IF EXISTS testCONJ956");
}

@BeforeAll
public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute("CREATE TABLE testCONJ956 (field varchar(300) NOT NULL)");
stmt.execute("CREATE TABLE StatementTest (t1 int not null primary key auto_increment, t2 int)");
stmt.execute(
"CREATE TABLE executeGenerated (t1 int not null primary key auto_increment, t2 int)");
Expand Down Expand Up @@ -102,6 +104,21 @@ public void getConnection() throws SQLException {
assertEquals(ResultSet.HOLD_CURSORS_OVER_COMMIT, stmt.getResultSetHoldability());
}

@Test
public void conj956() throws SQLException {
StringBuilder sb = new StringBuilder();
String sQuery = "SELECT EXISTS (SELECT 1 FROM testCONJ956 WHERE ((field=?)))";
for (int i = 1; i <= 300; i++) {
sb.append("a");
if (i < 204) {
continue;
}
PreparedStatement stmt = sharedConn.prepareStatement(sQuery);
stmt.setString(1, sb.toString());
stmt.executeQuery();
}
}

@Test
public void execute() throws SQLException {
Statement stmt = sharedConn.createStatement();
Expand Down

0 comments on commit e15fa25

Please sign in to comment.