[Libreoffice-commits] core.git: dbaccess/qa dbaccess/source
Tamas Bunth
tamas.bunth at collabora.co.uk
Fri Jul 6 08:38:04 UTC 2018
dbaccess/qa/extras/hsql_schema_import.cxx | 18 ++++++++++++++++++
dbaccess/source/filter/hsqldb/createparser.cxx | 7 +++++--
2 files changed, 23 insertions(+), 2 deletions(-)
New commits:
commit a91fe8558b4c8aa163069ebdb117d58239da74f2
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date: Tue Jun 26 13:15:07 2018 +0200
dbahsql: Look for properties only after name
Additional properties in SQL string like "DEFAULT" or "NOT NULL" should
be searched only after column name, because what if a column name is
"myEvilNOT NULLColumn"
Change-Id: I21f0755ba14c7267243d9999f044db4d16963387
Reviewed-on: https://gerrit.libreoffice.org/56462
Tested-by: Jenkins
Reviewed-by: Tamás Bunth <btomi96 at gmail.com>
diff --git a/dbaccess/qa/extras/hsql_schema_import.cxx b/dbaccess/qa/extras/hsql_schema_import.cxx
index 892be33d15e7..dd75eb2dc38c 100644
--- a/dbaccess/qa/extras/hsql_schema_import.cxx
+++ b/dbaccess/qa/extras/hsql_schema_import.cxx
@@ -42,6 +42,7 @@ public:
void testIntegerAutoincremental();
void testTimestampWithParam();
void testDefaultValueNow();
+ void testEvilNullColumnName();
// TODO testForeign, testDecomposer
CPPUNIT_TEST_SUITE(HsqlSchemaImportTest);
@@ -53,6 +54,7 @@ public:
CPPUNIT_TEST(testIntegerAutoincremental);
CPPUNIT_TEST(testTimestampWithParam);
CPPUNIT_TEST(testDefaultValueNow);
+ CPPUNIT_TEST(testEvilNullColumnName);
CPPUNIT_TEST_SUITE_END();
};
@@ -197,6 +199,22 @@ void HsqlSchemaImportTest::testDefaultValueNow()
CPPUNIT_ASSERT(fbSql.indexOf("\'NOW\'") > 0); // composed 'NOW'
}
+void HsqlSchemaImportTest::testEvilNullColumnName()
+{
+ OUString sql{ "CREATE CACHED TABLE \"myTable\"(\"id\" INTEGER NOT NULL PRIMARY KEY, "
+ "\"myEvilNOT NULLName\" "
+ "VARCHAR(20))" };
+
+ FbCreateStmtParser aCreateParser;
+ aCreateParser.parse(sql);
+
+ const auto& columns = aCreateParser.getColumnDef();
+ CPPUNIT_ASSERT_EQUAL(2_z, columns.size());
+ const ColumnDefinition* colVarchar = lcl_findByType(columns, css::sdbc::DataType::VARCHAR);
+ CPPUNIT_ASSERT(colVarchar != nullptr);
+ CPPUNIT_ASSERT(colVarchar->isNullable());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(HsqlSchemaImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/dbaccess/source/filter/hsqldb/createparser.cxx b/dbaccess/source/filter/hsqldb/createparser.cxx
index 2344ceb075fe..32abe25a8521 100644
--- a/dbaccess/source/filter/hsqldb/createparser.cxx
+++ b/dbaccess/source/filter/hsqldb/createparser.cxx
@@ -301,10 +301,13 @@ void CreateStmtParser::parseColumnPart(const OUString& sColumnPart)
if (isPrimaryKey)
m_PrimaryKeys.push_back(rColumnName);
+ const OUString sColumnWithoutName = sColumn.copy(sColumn.indexOf(typeParts.typeName));
+
ColumnDefinition aColDef(rColumnName, lcl_getDataTypeFromHsql(typeParts.typeName),
typeParts.params, isPrimaryKey,
- lcl_getAutoIncrementDefault(sColumn), lcl_isNullable(sColumn),
- bCaseInsensitive, lcl_getDefaultValue(sColumn));
+ lcl_getAutoIncrementDefault(sColumnWithoutName),
+ lcl_isNullable(sColumnWithoutName), bCaseInsensitive,
+ lcl_getDefaultValue(sColumnWithoutName));
m_aColumns.push_back(aColDef);
}
More information about the Libreoffice-commits
mailing list