Skip to content

Commit c31f2b6

Browse files
karenc-bqfjssilva
andauthored
Merge pull request from GHSA-vj9v-mpjv-qf74
Change-Id: I7b96bc52d0f2e6a77ef1623bf10644c7ca5b7bb4 Co-authored-by: Filipe Silva <[email protected]>
1 parent f86663f commit c31f2b6

File tree

25 files changed

+360
-466
lines changed

25 files changed

+360
-466
lines changed

src/legacy/java/com/mysql/jdbc/SocketFactoryWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -48,8 +48,8 @@ public class SocketFactoryWrapper extends StandardSocketFactory implements Socke
4848
com.mysql.jdbc.SocketFactory socketFactory;
4949

5050
@SuppressWarnings("deprecation")
51-
public SocketFactoryWrapper(Object legacyFactory) {
52-
this.socketFactory = (com.mysql.jdbc.SocketFactory) legacyFactory;
51+
public SocketFactoryWrapper(com.mysql.jdbc.SocketFactory legacyFactory) {
52+
this.socketFactory = legacyFactory;
5353
}
5454

5555
@SuppressWarnings({ "deprecation", "unchecked" })

src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -243,7 +243,7 @@ public static boolean isSupported(String scheme) {
243243
* an instance of {@link ConnectionUrl}.
244244
*/
245245
private ConnectionUrl getImplementingInstance(ConnectionUrlParser parser, Properties info) {
246-
return (ConnectionUrl) Util.getInstance(getImplementingClass(), new Class<?>[] { ConnectionUrlParser.class, Properties.class },
246+
return Util.getInstance(ConnectionUrl.class, this.implementingClass, new Class<?>[] { ConnectionUrlParser.class, Properties.class },
247247
new Object[] { parser, info }, null);
248248
}
249249
}
@@ -384,10 +384,9 @@ protected void setupPropertiesTransformer() {
384384
String propertiesTransformClassName = this.properties.get(PropertyKey.propertiesTransform.getKeyName());
385385
if (!isNullOrEmpty(propertiesTransformClassName)) {
386386
try {
387-
this.propertiesTransformer = (ConnectionPropertiesTransform) Class.forName(propertiesTransformClassName).newInstance();
388-
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | CJException e) {
389-
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
390-
Messages.getString("ConnectionString.9", new Object[] { propertiesTransformClassName, e.toString() }), e);
387+
this.propertiesTransformer = Util.getInstance(ConnectionPropertiesTransform.class, propertiesTransformClassName, null, null, null);
388+
} catch (CJException e) {
389+
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.9"), e);
391390
}
392391
}
393392
}

src/main/core-api/java/com/mysql/cj/exceptions/ExceptionFactory.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -30,14 +30,15 @@
3030
package com.mysql.cj.exceptions;
3131

3232
import java.net.BindException;
33+
import java.net.NetworkInterface;
34+
import java.net.SocketException;
3335

3436
import com.mysql.cj.Messages;
3537
import com.mysql.cj.conf.PropertyKey;
3638
import com.mysql.cj.conf.PropertySet;
3739
import com.mysql.cj.protocol.PacketReceivedTimeHolder;
3840
import com.mysql.cj.protocol.PacketSentTimeHolder;
3941
import com.mysql.cj.protocol.ServerSession;
40-
import com.mysql.cj.util.Util;
4142

4243
public class ExceptionFactory {
4344

@@ -101,9 +102,7 @@ public static CJException createException(String message, Throwable cause) {
101102
}
102103

103104
public static <T extends CJException> T createException(Class<T> clazz, String message, Throwable cause) {
104-
105105
T sqlEx = createException(clazz, message);
106-
107106
if (cause != null) {
108107
try {
109108
sqlEx.initCause(cause);
@@ -282,8 +281,13 @@ public static String createLinkFailureMessageBasedOnHeuristics(PropertySet prope
282281
//
283282
if (underlyingException instanceof BindException) {
284283
String localSocketAddress = propertySet.getStringProperty(PropertyKey.localSocketAddress).getValue();
285-
exceptionMessageBuf.append(localSocketAddress != null && !Util.interfaceExists(localSocketAddress)
286-
? Messages.getString("CommunicationsException.LocalSocketAddressNotAvailable")
284+
boolean interfaceNotAvaliable;
285+
try {
286+
interfaceNotAvaliable = localSocketAddress != null && NetworkInterface.getByName(localSocketAddress) == null;
287+
} catch (SocketException e1) {
288+
interfaceNotAvaliable = false;
289+
}
290+
exceptionMessageBuf.append(interfaceNotAvaliable ? Messages.getString("CommunicationsException.LocalSocketAddressNotAvailable")
287291
: Messages.getString("CommunicationsException.TooManyClientConnections"));
288292
}
289293
}
@@ -303,5 +307,4 @@ public static String createLinkFailureMessageBasedOnHeuristics(PropertySet prope
303307

304308
return exceptionMessageBuf.toString();
305309
}
306-
307310
}
Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
33
*
44
* This program is free software; you can redistribute it and/or modify it under
55
* the terms of the GNU General Public License, version 2.0, as published by the
@@ -29,7 +29,7 @@
2929

3030
package com.mysql.cj.exceptions;
3131

32-
import java.util.Iterator;
32+
import java.util.LinkedList;
3333
import java.util.List;
3434
import java.util.Properties;
3535
import java.util.stream.Collectors;
@@ -38,53 +38,34 @@
3838
import com.mysql.cj.util.Util;
3939

4040
public class ExceptionInterceptorChain implements ExceptionInterceptor {
41-
List<ExceptionInterceptor> interceptors;
41+
private List<ExceptionInterceptor> interceptors;
4242

4343
public ExceptionInterceptorChain(String interceptorClasses, Properties props, Log log) {
44-
this.interceptors = Util.<ExceptionInterceptor> loadClasses(interceptorClasses, "Connection.BadExceptionInterceptor", this).stream()
45-
.map(o -> o.init(props, log)).collect(Collectors.toList());
44+
this.interceptors = Util.loadClasses(ExceptionInterceptor.class, interceptorClasses, "Connection.BadExceptionInterceptor", null).stream()
45+
.map(i -> i.init(props, log)).collect(Collectors.toCollection(LinkedList::new));
4646
}
4747

4848
public void addRingZero(ExceptionInterceptor interceptor) {
4949
this.interceptors.add(0, interceptor);
5050
}
5151

5252
public Exception interceptException(Exception sqlEx) {
53-
if (this.interceptors != null) {
54-
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();
55-
56-
while (iter.hasNext()) {
57-
sqlEx = iter.next().interceptException(sqlEx);
58-
}
53+
for (ExceptionInterceptor ie : this.interceptors) {
54+
sqlEx = ie.interceptException(sqlEx);
5955
}
60-
6156
return sqlEx;
6257
}
6358

6459
public void destroy() {
65-
if (this.interceptors != null) {
66-
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();
67-
68-
while (iter.hasNext()) {
69-
iter.next().destroy();
70-
}
71-
}
72-
60+
this.interceptors.forEach(ExceptionInterceptor::destroy);
7361
}
7462

7563
public ExceptionInterceptor init(Properties properties, Log log) {
76-
if (this.interceptors != null) {
77-
Iterator<ExceptionInterceptor> iter = this.interceptors.iterator();
78-
79-
while (iter.hasNext()) {
80-
iter.next().init(properties, log);
81-
}
82-
}
64+
this.interceptors = this.interceptors.stream().map(i -> i.init(properties, log)).collect(Collectors.toCollection(LinkedList::new));
8365
return this;
8466
}
8567

8668
public List<ExceptionInterceptor> getInterceptors() {
8769
return this.interceptors;
8870
}
89-
9071
}

0 commit comments

Comments
 (0)