Skip to content

Commit

Permalink
Fix for Bug#94051 (29261254), Not recommended default for 'allowLoadL…
Browse files Browse the repository at this point in the history
…ocalInfile'.
  • Loading branch information
fjssilva committed Jan 25, 2019
1 parent 76adb77 commit 79a4336
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 21 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.15

- Fix for Bug#94051 (29261254), Not recommended default for 'allowLoadLocalInfile'.

Version 8.0.14

- WL#12298, Connectors: Expose metadata about source and binaries in unified way.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -216,7 +216,7 @@ public enum AuthMech { // xdevapi.auth
new StringPropertyDefinition(PropertyKey.profilerEventHandler, "com.mysql.cj.log.LoggingProfilerEventHandler", RUNTIME_MODIFIABLE,
Messages.getString("ConnectionProperties.profilerEventHandler"), "5.1.6", CATEGORY_DEBUGING_PROFILING, Integer.MIN_VALUE),

new BooleanPropertyDefinition(PropertyKey.allowLoadLocalInfile, DEFAULT_VALUE_TRUE, RUNTIME_MODIFIABLE,
new BooleanPropertyDefinition(PropertyKey.allowLoadLocalInfile, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
Messages.getString("ConnectionProperties.loadDataLocal"), "3.0.3", CATEGORY_SECURITY, Integer.MAX_VALUE),

new BooleanPropertyDefinition(PropertyKey.allowMultiQueries, DEFAULT_VALUE_FALSE, RUNTIME_MODIFIABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ ConnectionProperties.categoryUserDefined=User-defined properties
# ConnectionProperty Descriptions
#

ConnectionProperties.loadDataLocal=Should the driver allow use of 'LOAD DATA LOCAL INFILE...' (defaults to 'true').
ConnectionProperties.loadDataLocal=Should the driver allow use of 'LOAD DATA LOCAL INFILE...'?
ConnectionProperties.allowMasterDownConnections=By default, a replication-aware connection will fail to connect when configured master hosts are all unavailable at initial connection. Setting this property to 'true' allows to establish the initial connection, by failing over to the slave servers, in read-only state. It won't prevent subsequent failures when switching back to the master hosts i.e. by setting the replication connection to read/write state.
ConnectionProperties.allowSlaveDownConnections=By default, a replication-aware connection will fail to connect when configured slave hosts are all unavailable at initial connection. Setting this property to 'true' allows to establish the initial connection. It won't prevent failures when switching to slaves i.e. by setting the replication connection to read-only state. The property 'readFromMasterWhenNoSlaves' should be used for this purpose.
ConnectionProperties.readFromMasterWhenNoSlaves=Replication-aware connections distribute load by using the master hosts when in read/write state and by using the slave hosts when in read-only state. If, when setting the connection to read-only state, none of the slave hosts are available, an SQLExeception is thrown back. Setting this property to 'true' allows to fail over to the master hosts, while setting the connection state to read-only, when no slave hosts are available at switch instant.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -4780,6 +4780,7 @@ public void testBug11237() throws Exception {
}

Properties props = new Properties();
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
props.setProperty(PropertyKey.useCompression.getKeyName(), "true");
Connection conn1 = getConnectionWithProps(props);
Statement stmt1 = conn1.createStatement();
Expand All @@ -4790,7 +4791,6 @@ public void testBug11237() throws Exception {
((JdbcConnection) conn1).getServerVersion()));

assertTrue(updateCount == loops);

}

public void testStackOverflowOnMissingInterceptor() throws Exception {
Expand Down
17 changes: 15 additions & 2 deletions src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -60,6 +60,7 @@
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Statement;
Expand Down Expand Up @@ -2376,8 +2377,20 @@ public void testLoadData() throws Exception {
} else {
fileNameBuf = new StringBuilder(tempFile.getAbsolutePath());
}
final String fileName = fileNameBuf.toString();

int updateCount = this.stmt
assertThrows(SQLSyntaxErrorException.class, "The used command is not allowed with this MySQL version", () -> {
this.stmt.executeUpdate("LOAD DATA LOCAL INFILE '" + fileName + "' INTO TABLE loadDataRegress CHARACTER SET "
+ CharsetMapping.getMysqlCharsetForJavaEncoding(
((MysqlConnection) this.conn).getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(),
this.serverVersion));
return null;
});

Properties props = new Properties();
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);
int updateCount = testConn.createStatement()
.executeUpdate("LOAD DATA LOCAL INFILE '" + fileNameBuf.toString() + "' INTO TABLE loadDataRegress CHARACTER SET "
+ CharsetMapping.getMysqlCharsetForJavaEncoding(
((MysqlConnection) this.conn).getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(),
Expand Down
29 changes: 20 additions & 9 deletions src/test/java/testsuite/simple/ConnectionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -53,6 +53,7 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Timestamp;
Expand Down Expand Up @@ -757,6 +758,7 @@ public void testLocalInfileWithUrl() throws Exception {
createTable("testLocalInfileWithUrl", "(field1 LONGTEXT)");

Properties props = new Properties();
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
props.setProperty(PropertyKey.allowUrlInLocalInfile.getKeyName(), "true");

Connection loadConn = getConnectionWithProps(props);
Expand Down Expand Up @@ -817,17 +819,26 @@ public void testLocalInfileDisabled() throws Exception {
output.flush();
output.close();

Connection loadConn = getConnectionWithProps(new Properties());
// Test load local infile support disabled via client capabilities by default.
assertThrows(SQLSyntaxErrorException.class, "The used command is not allowed with this MySQL version", () -> {
this.stmt.executeUpdate("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled");
return null;
});

// Test load local infile support enabled via client capabilities but disabled on the connector.
Properties props = new Properties();
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
Connection loadConn = getConnectionWithProps(props);

try {
// have to do this after connect, otherwise it's the server that's enforcing it
// Must be set after connect, otherwise it's the server that's enforcing it.
((com.mysql.cj.jdbc.JdbcConnection) loadConn).getPropertySet().getProperty(PropertyKey.allowLoadLocalInfile).setValue(false);
try {
loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled");
fail("Should've thrown an exception.");
} catch (SQLException sqlEx) {
assertEquals(MysqlErrorNumbers.SQL_STATE_GENERAL_ERROR, sqlEx.getSQLState());
}

assertThrows(SQLException.class, "Server asked for stream in response to LOAD DATA LOCAL INFILE but functionality is disabled at client by "
+ "'allowLoadLocalInfile' being set to 'false'\\.", () -> {
loadConn.createStatement().execute("LOAD DATA LOCAL INFILE '" + infile.getCanonicalPath() + "' INTO TABLE testLocalInfileDisabled");
return null;
});

assertFalse(loadConn.createStatement().executeQuery("SELECT * FROM testLocalInfileDisabled").next());
} finally {
Expand Down
17 changes: 12 additions & 5 deletions src/test/java/testsuite/simple/StatementsTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
*
* 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 @@ -1838,21 +1838,28 @@ public void testLocalInfileHooked() throws Exception {
createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
InputStream stream = new ByteArrayInputStream(streamData.getBytes());

Properties props = new Properties();
props.setProperty(PropertyKey.allowLoadLocalInfile.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);
Statement testStmt = testConn.createStatement();

try {
((com.mysql.cj.jdbc.JdbcStatement) this.stmt).setLocalInfileInputStream(stream);
this.stmt.execute(
((com.mysql.cj.jdbc.JdbcStatement) testStmt).setLocalInfileInputStream(stream);
testStmt.execute(
"LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET " + CharsetMapping.getMysqlCharsetForJavaEncoding(
((MysqlConnection) this.conn).getPropertySet().getStringProperty(PropertyKey.characterEncoding).getValue(), this.serverVersion));
assertEquals(-1, stream.read());
this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
this.rs = testStmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
this.rs.next();
assertEquals("abcd", this.rs.getString(1));
this.rs.next();
assertEquals("efgh", this.rs.getString(1));
this.rs.next();
assertEquals("ijkl", this.rs.getString(1));
} finally {
((com.mysql.cj.jdbc.JdbcStatement) this.stmt).setLocalInfileInputStream(null);
((com.mysql.cj.jdbc.JdbcStatement) testStmt).setLocalInfileInputStream(null);
testConn.close();
}
}

Expand Down

0 comments on commit 79a4336

Please sign in to comment.