Skip to content

Commit 97b5d11

Browse files
committed
Fix for Bug#84365 (33425867), INSERT..VALUE with VALUES function lead to
a StringIndexOutOfBoundsException.
1 parent a82104b commit 97b5d11

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.28
55

6+
- Fix for Bug#84365 (33425867), INSERT..VALUE with VALUES function lead to a StringIndexOutOfBoundsException.
7+
68
- Fix for Bug#105211 (33468860), class java.time.LocalDate cannot be cast to class java.sql.Date.
79

810
- Fix for Bug#101389 (32089018), GETWARNINGS SHOULD CHECK WARNING COUNT BEFORE SENDING SHOW.

src/main/core-api/java/com/mysql/cj/ParseInfo.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,19 @@ private String extractValuesClause(String sql, String quoteCharStr) {
244244
int indexOfValues = -1;
245245
int valuesSearchStart = this.statementStartPos;
246246

247+
int indexOfFirstEqualsChar = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "=", quoteCharStr, quoteCharStr, SearchMode.__MRK_COM_MYM_HNT_WS);
248+
247249
while (indexOfValues == -1) {
248-
// TODO: also support "VALUE" clause
250+
// "VALUE" is a synonym of "VALUES" clause, so checking for the first one
249251
if (quoteCharStr.length() > 0) {
250-
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUES", quoteCharStr, quoteCharStr, SearchMode.__MRK_COM_MYM_HNT_WS);
252+
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUE", quoteCharStr, quoteCharStr, SearchMode.__MRK_COM_MYM_HNT_WS);
251253
} else {
252-
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUES");
254+
indexOfValues = StringUtils.indexOfIgnoreCase(valuesSearchStart, sql, "VALUE");
255+
}
256+
257+
if (indexOfFirstEqualsChar > 0 && indexOfValues > indexOfFirstEqualsChar) {
258+
// VALUES clause always precedes the first '=' occurrence, otherwise it's a values() function
259+
indexOfValues = -1;
253260
}
254261

255262
// TODO: this doesn't support queries like "INSERT INTO t /* foo */VALUES/* bar */(...)" although its valid. Replace by StringInspector.

src/test/java/testsuite/regression/StatementRegressionTest.java

+47
Original file line numberDiff line numberDiff line change
@@ -11826,4 +11826,51 @@ public void testBug105211() throws Exception {
1182611826
con.close();
1182711827
} while (useSPS = !useSPS);
1182811828
}
11829+
11830+
/**
11831+
* Test fix for Bug#84365 (33425867), INSERT..VALUE with VALUES function lead to a StringIndexOutOfBoundsException.
11832+
*
11833+
* @throws Exception
11834+
*/
11835+
@Test
11836+
public void testBug84365() throws Exception {
11837+
createTable("testBug84365", "(id int(11) NOT NULL, name varchar(25) DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=latin1");
11838+
11839+
Properties props = new Properties();
11840+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11841+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11842+
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), "true");
11843+
11844+
for (boolean useSSPS : new boolean[] { false, true }) {
11845+
11846+
this.stmt.executeUpdate("truncate table testBug84365");
11847+
11848+
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "" + useSSPS);
11849+
Connection testConn = getConnectionWithProps(props);
11850+
11851+
PreparedStatement st = testConn.prepareStatement("insert into testBug84365(id, name) VALUES(?,?) on duplicate key update id = values(id) + 1");
11852+
st.setInt(1, 1);
11853+
st.setString(2, "Name1");
11854+
st.execute();
11855+
st.close();
11856+
11857+
st = testConn.prepareStatement("insert into testBug84365(id, name) VALUE(?,?) on duplicate key update id = values(id) + 1");
11858+
st.setInt(1, 2);
11859+
st.setString(2, "Name2");
11860+
st.execute();
11861+
st.close();
11862+
11863+
st = testConn.prepareStatement("insert into testBug84365 set id = 2 on duplicate key update id = values(id) + 1");
11864+
st.execute();
11865+
11866+
this.rs = testConn.createStatement().executeQuery("select * from testBug84365 order by id");
11867+
assertTrue(this.rs.next());
11868+
assertEquals(1, this.rs.getInt("id"));
11869+
assertEquals("Name1", this.rs.getString("name"));
11870+
assertTrue(this.rs.next());
11871+
assertEquals(3, this.rs.getInt("id"));
11872+
assertEquals("Name2", this.rs.getString("name"));
11873+
assertFalse(this.rs.next());
11874+
}
11875+
}
1182911876
}

0 commit comments

Comments
 (0)