Skip to content

Commit

Permalink
Fix for Bug#23204652, Bug#71929 (18346501) and Bug#103612 (32902019).
Browse files Browse the repository at this point in the history
Fix for Bug#23204652, CURSOR POSITIONING API'S DOESNOT CHECK THE VALIDITY OF RESULTSET.
Fix for Bug#71929 (18346501), Prefixing query with double comments cancels query DML validation.
Fix for Bug#103612 (32902019), Incorrectly identified WITH...SELECT as unsafe for read-only connections.
  • Loading branch information
fjssilva committed Sep 8, 2021
1 parent 509f184 commit ade4a41
Show file tree
Hide file tree
Showing 19 changed files with 2,007 additions and 998 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

Version 8.0.27

- Fix for Bug#103612 (32902019), Incorrectly identified WITH...SELECT as unsafe for read-only connections.

- Fix for Bug#71929 (18346501), Prefixing query with double comments cancels query DML validation.

- Fix for Bug#23204652, CURSOR POSITIONING API'S DOESNOT CHECK THE VALIDITY OF RESULTSET.

- Fix for Bug#28725534, MULTI HOST CONNECTION WOULD BLOCK IN CONNECTION POOLING.

- Fix for Bug#95139 (29807572), CACHESERVERCONFIGURATION APPEARS TO THWART CHARSET DETECTION.
Expand Down
7 changes: 3 additions & 4 deletions src/build/java/instrumentation/TranslateExceptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -292,7 +292,7 @@ public static void main(String[] args) throws Exception {
/*
* java.sql.PreparedStatement extends java.sql.Statement (java.sql.Statement extends java.sql.Wrapper)
*/
// com.mysql.cj.jdbc.PreparedStatement extends com.mysql.cj.jdbc.StatementImpl implements java.sql.PreparedStatement
// com.mysql.cj.jdbc.ClientPreparedStatement extends com.mysql.cj.jdbc.StatementImpl implements java.sql.PreparedStatement
clazz = pool.get(ClientPreparedStatement.class.getName());
instrumentJdbcMethods(clazz, java.sql.PreparedStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
instrumentJdbcMethods(clazz, JdbcStatement.class, true, EXCEPTION_INTERCEPTOR_GETTER);
Expand All @@ -318,7 +318,6 @@ public static void main(String[] args) throws Exception {
catchRuntimeException(clazz, clazz.getDeclaredMethod("getParameterBindings", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
catchRuntimeException(clazz, clazz.getDeclaredMethod("initializeFromParseInfo", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
catchRuntimeException(clazz, clazz.getDeclaredMethod("isNull", new CtClass[] { CtClass.intType }), EXCEPTION_INTERCEPTOR_GETTER);
catchRuntimeException(clazz, clazz.getDeclaredMethod("isSelectQuery", new CtClass[] {}), EXCEPTION_INTERCEPTOR_GETTER);
catchRuntimeException(clazz, clazz.getDeclaredMethod("prepareBatchedInsertSQL", new CtClass[] { ctJdbcConnection, CtClass.intType }),
EXCEPTION_INTERCEPTOR_GETTER);
catchRuntimeException(clazz,
Expand All @@ -328,7 +327,7 @@ public static void main(String[] args) throws Exception {
clazz.writeFile(args[0]);

/*
* com.mysql.cj.jdbc.ServerPreparedStatement extends PreparedStatement
* com.mysql.cj.jdbc.ServerPreparedStatement extends ClientPreparedStatement
*/
clazz = pool.get(ServerPreparedStatement.class.getName());
instrumentJdbcMethods(clazz, java.sql.PreparedStatement.class, false, EXCEPTION_INTERCEPTOR_GETTER);
Expand Down
497 changes: 285 additions & 212 deletions src/main/core-api/java/com/mysql/cj/ParseInfo.java

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/main/core-api/java/com/mysql/cj/QueryReturnType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
* Free Software Foundation.
*
* This program is also distributed with certain software (including but not
* limited to OpenSSL) that is licensed under separate terms, as designated in a
* particular file or component or in included license documentation. The
* authors of MySQL hereby grant you an additional permission to link the
* program and your derivative works with the separately licensed software that
* they have included with MySQL.
*
* Without limiting anything contained in the foregoing, this file, which is
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
* version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

package com.mysql.cj;

/**
* The possible return types from executing queries.
*/
public enum QueryReturnType {
PRODUCES_RESULT_SET, MAY_PRODUCE_RESULT_SET, DOES_NOT_PRODUCE_RESULT_SET, NONE;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -49,6 +49,7 @@
import com.mysql.cj.exceptions.ExceptionFactory;
import com.mysql.cj.exceptions.UnsupportedConnectionStringException;
import com.mysql.cj.exceptions.WrongArgumentException;
import com.mysql.cj.util.SearchMode;
import com.mysql.cj.util.StringUtils;

/**
Expand Down Expand Up @@ -178,7 +179,7 @@ private void parseAuthoritySection() {
}

List<String> authoritySegments = StringUtils.split(this.authority, HOSTS_SEPARATOR, HOSTS_LIST_OPENING_MARKERS, HOSTS_LIST_CLOSING_MARKERS, true,
StringUtils.SEARCH_MODE__MRK_WS);
SearchMode.__MRK_WS);
for (String hi : authoritySegments) {
parseAuthoritySegment(hi);
}
Expand Down Expand Up @@ -354,7 +355,7 @@ private List<HostInfo> buildHostInfoResortingToSubHostsListParser(String user, S
if (matcher.matches()) {
String hosts = matcher.group("hosts");
List<String> hostsList = StringUtils.split(hosts, HOSTS_SEPARATOR, HOSTS_LIST_OPENING_MARKERS, HOSTS_LIST_CLOSING_MARKERS, true,
StringUtils.SEARCH_MODE__MRK_WS);
SearchMode.__MRK_WS);
// One single element could, in fact, be an IPv6 stripped from its delimiters.
boolean maybeIPv6 = hostsList.size() == 1 && hostsList.get(0).matches("(?i)^[\\dabcdef:]+$");
List<HostInfo> hostInfoList = new ArrayList<>();
Expand Down
124 changes: 124 additions & 0 deletions src/main/core-api/java/com/mysql/cj/util/SearchMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
* Free Software Foundation.
*
* This program is also distributed with certain software (including but not
* limited to OpenSSL) that is licensed under separate terms, as designated in a
* particular file or component or in included license documentation. The
* authors of MySQL hereby grant you an additional permission to link the
* program and your derivative works with the separately licensed software that
* they have included with MySQL.
*
* Without limiting anything contained in the foregoing, this file, which is
* part of MySQL Connector/J, is also subject to the Universal FOSS Exception,
* version 1.0, a copy of which can be found at
* http://oss.oracle.com/licenses/universal-foss-exception.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

package com.mysql.cj.util;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

/**
* Search mode flags enumeration. Primarily used by {@link StringInspector}.
*/
public enum SearchMode {
/**
* Allow backslash escapes.
*/
ALLOW_BACKSLASH_ESCAPE,
/**
* Skip between markers (quoted text, quoted identifiers, text between parentheses).
*/
SKIP_BETWEEN_MARKERS,
/**
* Skip between block comments ("/* text... *\/") but not between hint blocks.
*/
SKIP_BLOCK_COMMENTS,
/**
* Skip line comments ("-- text...", "# text...").
*/
SKIP_LINE_COMMENTS,
/**
* Skip MySQL specific markers ("/*![12345]" and "*\/") but not their contents.
*/
SKIP_MYSQL_MARKERS,
/**
* Skip hint blocks ("/*+ text... *\/").
*/
SKIP_HINT_BLOCKS,
/**
* Skip white space.
*/
SKIP_WHITE_SPACE,
/**
* Dummy search mode. Does nothing.
*/
VOID;

/*
* Convenience EnumSets for several SearchMode combinations
*/

/**
* Full search mode: allow backslash escape, skip between markers, skip block comments, skip line comments, skip MySQL markers, skip hint blocks and skip
* white space.
* This is technically equivalent to __BSE_MRK_COM_MYM_HNT_WS.
*/
public static final Set<SearchMode> __FULL = Collections.unmodifiableSet(EnumSet.allOf(SearchMode.class));

/**
* Search mode: allow backslash escape, skip between markers, skip block comments, skip line comments, skip MySQL markers, skip hint blocks and skip
* white space.
*/
public static final Set<SearchMode> __BSE_MRK_COM_MYM_HNT_WS = Collections.unmodifiableSet(EnumSet.of(ALLOW_BACKSLASH_ESCAPE, SKIP_BETWEEN_MARKERS,
SKIP_BLOCK_COMMENTS, SKIP_LINE_COMMENTS, SKIP_MYSQL_MARKERS, SKIP_HINT_BLOCKS, SKIP_WHITE_SPACE));

/**
* Search mode: skip between markers, skip block comments, skip line comments, skip MySQL markers, skip hint blocks and skip white space.
*/
public static final Set<SearchMode> __MRK_COM_MYM_HNT_WS = Collections
.unmodifiableSet(EnumSet.of(SKIP_BETWEEN_MARKERS, SKIP_BLOCK_COMMENTS, SKIP_LINE_COMMENTS, SKIP_MYSQL_MARKERS, SKIP_HINT_BLOCKS, SKIP_WHITE_SPACE));

/**
* Search mode: allow backslash escape, skip block comments, skip line comments, skip MySQL markers, skip hint blocks and skip white space.
*/
public static final Set<SearchMode> __BSE_COM_MYM_HNT_WS = Collections.unmodifiableSet(
EnumSet.of(ALLOW_BACKSLASH_ESCAPE, SKIP_BLOCK_COMMENTS, SKIP_LINE_COMMENTS, SKIP_MYSQL_MARKERS, SKIP_HINT_BLOCKS, SKIP_WHITE_SPACE));

/**
* Search mode: skip block comments, skip line comments, skip MySQL markers, skip hint blocks and skip white space.
*/
public static final Set<SearchMode> __COM_MYM_HNT_WS = Collections
.unmodifiableSet(EnumSet.of(SKIP_BLOCK_COMMENTS, SKIP_LINE_COMMENTS, SKIP_MYSQL_MARKERS, SKIP_HINT_BLOCKS, SKIP_WHITE_SPACE));

/**
* Search mode: allow backslash escape, skip between markers and skip white space.
*/
public static final Set<SearchMode> __BSE_MRK_WS = Collections.unmodifiableSet(EnumSet.of(ALLOW_BACKSLASH_ESCAPE, SKIP_BETWEEN_MARKERS, SKIP_WHITE_SPACE));

/**
* Search mode: skip between markers and skip white space.
*/
public static final Set<SearchMode> __MRK_WS = Collections.unmodifiableSet(EnumSet.of(SKIP_BETWEEN_MARKERS, SKIP_WHITE_SPACE));

/**
* Empty search mode.
* There must be at least one element so that the Set may be later duplicated if needed.
*/
public static final Set<SearchMode> __NONE = Collections.unmodifiableSet(EnumSet.of(VOID));
}
Loading

0 comments on commit ade4a41

Please sign in to comment.