Skip to content

Commit

Permalink
Fix for Bug#67828 (Bug#15967406), Crashing applets due to reading fil…
Browse files Browse the repository at this point in the history
…e.encoding system property.

Change-Id: Ic65898094327acfc4440736a4fa9c3a2aca661de
  • Loading branch information
fjssilva committed Sep 1, 2022
1 parent 4221940 commit 83bbcac
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 34 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.31

- Fix for Bug#67828 (Bug#15967406), Crashing applets due to reading file.encoding system property.

- WL#15259, Review maven publishing process.

- Fix for Bug#107222 (Bug#34150112), ClientPreparedStatement.toString() no longer interpolates byte arrays.
Expand Down
3 changes: 1 addition & 2 deletions src/main/core-api/java/com/mysql/cj/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2021, Oracle and/or its affiliates.
* Copyright (c) 2002, 2022, 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 @@ -58,7 +58,6 @@ public class Constants {
public static final String OS_NAME = System.getProperty(PropertyDefinitions.SYSP_os_name);
public static final String OS_ARCH = System.getProperty(PropertyDefinitions.SYSP_os_arch);
public static final String OS_VERSION = System.getProperty(PropertyDefinitions.SYSP_os_version);
public static final String PLATFORM_ENCODING = System.getProperty(PropertyDefinitions.SYSP_file_encoding);

public static final String CJ_NAME = "@MYSQL_CJ_DISPLAY_PROD_NAME@";
public static final String CJ_FULL_NAME = "@MYSQL_CJ_FULL_PROD_NAME@";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class PropertyDefinitions {
public static final String SYSP_os_name = "os.name";
public static final String SYSP_os_arch = "os.arch";
public static final String SYSP_os_version = "os.version";
public static final String SYSP_file_encoding = "file.encoding";

/*
* Operational system properties.
Expand Down
34 changes: 3 additions & 31 deletions src/main/core-impl/java/com/mysql/cj/NativeCharsetSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

package com.mysql.cj;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -122,33 +120,11 @@ public class NativeCharsetSettings extends CharsetMapping implements CharsetSett
private static final Map<String, Map<String, String>> customJavaEncodingUcToCharsetNameByUrl = new HashMap<>();
private static final Map<String, Set<String>> customMultibyteEncodingsByUrl = new HashMap<>();

/**
* We store the platform 'encoding' here, only used to avoid munging filenames for LOAD DATA LOCAL INFILE...
*/
private static Charset jvmPlatformCharset = null;

/**
* Does the character set of this connection match the character set of the platform
*/
private boolean platformDbCharsetMatches = true; // changed once we've connected.

static {
OutputStreamWriter outWriter = null;
// Use the I/O system to get the encoding (if possible), to avoid security restrictions on System.getProperty("file.encoding") in applets (why is that restricted?)
try {
outWriter = new OutputStreamWriter(new ByteArrayOutputStream());
jvmPlatformCharset = Charset.forName(outWriter.getEncoding());
} finally {
try {
if (outWriter != null) {
outWriter.close();
}
} catch (IOException ioEx) {
// ignore
}
}
}

private NativeMessageBuilder getCommandBuilder() {
if (this.commandBuilder == null) {
this.commandBuilder = new NativeMessageBuilder(this.serverSession.supportsQueryAttributes());
Expand All @@ -157,19 +133,15 @@ private NativeMessageBuilder getCommandBuilder() {
}

/**
* Determines if the database charset is the same as the platform charset
* Determines if the connection charset is the same as the platform charset
*/
private void checkForCharsetMismatch() {
String characterEncodingValue = this.characterEncoding.getValue();
if (characterEncodingValue != null) {
Charset characterEncodingCs = Charset.forName(characterEncodingValue);
Charset encodingToCheck = jvmPlatformCharset;

if (encodingToCheck == null) {
encodingToCheck = Charset.forName(Constants.PLATFORM_ENCODING);
}
Charset encodingToCheck = Charset.defaultCharset();

this.platformDbCharsetMatches = encodingToCheck == null ? false : encodingToCheck.equals(characterEncodingCs);
this.platformDbCharsetMatches = encodingToCheck.equals(characterEncodingCs);
}
}

Expand Down

0 comments on commit 83bbcac

Please sign in to comment.