Skip to content

Commit 13f06c3

Browse files
committed
Fix for Bug#30636056, ResultSetUtil.resultSetToMap() can be unsafe to use.
1 parent 179957f commit 13f06c3

File tree

3 files changed

+6
-50
lines changed

3 files changed

+6
-50
lines changed

src/com/mysql/jdbc/CallableStatement.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/J is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
@@ -179,7 +179,6 @@ protected class CallableStatementParamInfo implements ParameterMetaData {
179179
this.numParameters = this.parameterList.size();
180180
}
181181

182-
@SuppressWarnings("synthetic-access")
183182
CallableStatementParamInfo(java.sql.ResultSet paramTypesRs) throws SQLException {
184183
boolean hadRows = paramTypesRs.last();
185184

src/com/mysql/jdbc/Util.java

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/J is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
@@ -23,7 +23,6 @@
2323

2424
package com.mysql.jdbc;
2525

26-
import java.io.ObjectInputStream;
2726
import java.io.PrintWriter;
2827
import java.io.StringWriter;
2928
import java.io.UnsupportedEncodingException;
@@ -297,27 +296,6 @@ private static RandStructcture randomInit(long seed1, long seed2) {
297296
return randStruct;
298297
}
299298

300-
/**
301-
* Given a ResultSet and an index into the columns of that ResultSet, read
302-
* binary data from the column which represents a serialized object, and
303-
* re-create the object.
304-
*
305-
* @param resultSet
306-
* the ResultSet to use.
307-
* @param index
308-
* an index into the ResultSet.
309-
* @return the object if it can be de-serialized
310-
* @throws Exception
311-
* if an error occurs
312-
*/
313-
public static Object readObject(java.sql.ResultSet resultSet, int index) throws Exception {
314-
ObjectInputStream objIn = new ObjectInputStream(resultSet.getBinaryStream(index));
315-
Object obj = objIn.readObject();
316-
objIn.close();
317-
318-
return obj;
319-
}
320-
321299
private static double rnd(RandStructcture randStruct) {
322300
randStruct.seed1 = ((randStruct.seed1 * 3) + randStruct.seed2) % randStruct.maxValue;
323301
randStruct.seed2 = (randStruct.seed1 + randStruct.seed2 + 33) % randStruct.maxValue;
@@ -461,27 +439,6 @@ public static boolean interfaceExists(String hostname) {
461439
}
462440
}
463441

464-
@SuppressWarnings({ "rawtypes", "unchecked" })
465-
public static void resultSetToMap(Map mappedValues, java.sql.ResultSet rs) throws SQLException {
466-
while (rs.next()) {
467-
mappedValues.put(rs.getObject(1), rs.getObject(2));
468-
}
469-
}
470-
471-
@SuppressWarnings({ "rawtypes", "unchecked" })
472-
public static void resultSetToMap(Map mappedValues, java.sql.ResultSet rs, int key, int value) throws SQLException {
473-
while (rs.next()) {
474-
mappedValues.put(rs.getObject(key), rs.getObject(value));
475-
}
476-
}
477-
478-
@SuppressWarnings({ "rawtypes", "unchecked" })
479-
public static void resultSetToMap(Map mappedValues, java.sql.ResultSet rs, String key, String value) throws SQLException {
480-
while (rs.next()) {
481-
mappedValues.put(rs.getObject(key), rs.getObject(value));
482-
}
483-
}
484-
485442
public static Map<Object, Object> calculateDifferences(Map<?, ?> map1, Map<?, ?> map2) {
486443
Map<Object, Object> diffMap = new HashMap<Object, Object>();
487444

src/com/mysql/jdbc/interceptors/ServerStatusDiffInterceptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
33
44
The MySQL Connector/J is licensed under the terms of the GPLv2
55
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
@@ -63,15 +63,15 @@ private void populateMapWithSessionStatusValues(Connection connection, Map<Strin
6363

6464
try {
6565
toPopulate.clear();
66-
6766
stmt = connection.createStatement();
6867
rs = stmt.executeQuery("SHOW SESSION STATUS");
69-
Util.resultSetToMap(toPopulate, rs);
68+
while (rs.next()) {
69+
toPopulate.put(rs.getString(1), rs.getString(2));
70+
}
7071
} finally {
7172
if (rs != null) {
7273
rs.close();
7374
}
74-
7575
if (stmt != null) {
7676
stmt.close();
7777
}

0 commit comments

Comments
 (0)