Issue Details (XML | Word | Printable)

Key: DERBY-4042
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Knut Anders Hatlen
Reporter: Knut Anders Hatlen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Derby

org.apache.derby.impl.load.Import needs to escape single quotes

Created: 31/Jan/09 09:31 AM   Updated: 30/Jun/09 04:12 PM
Component/s: Tools
Affects Version/s: 10.4.2.0
Fix Version/s: 10.5.1.1

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works d4042-1.diff 2009-02-01 11:01 AM Knut Anders Hatlen 14 kB
HTML File Licensed for inclusion in ASF works releaseNote.html 2009-03-17 12:15 PM Knut Anders Hatlen 5 kB
File Licensed for inclusion in ASF works testfix.diff 2009-02-04 11:22 AM Knut Anders Hatlen 5 kB

Issue & fix info: Release Note Needed
Resolution Date: 17/Mar/09 12:16 PM


 Description  « Hide
The code that builds the SQL statement that invokes the Import VTI doesn't properly escape single quotes. This causes problems for users, see: http://mail-archives.apache.org/mod_mbox/db-derby-user/200901.mbox/%3c21754463.post@talk.nabble.com%3e

Import.performImport() is the method that needs to be fixed.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Knut Anders Hatlen added a comment - 31/Jan/09 10:29 AM
There are users who have come across this issue and have found out how to trick Derby into accepting strings with quotes in them, so I'm flagging the issue with "Existing Application Impact" and "Release Note Needed", since those users will have to remove the extra escape characters from their applications after the issue has been fixed.

Knut Anders Hatlen added a comment - 01/Feb/09 11:01 AM
Attached is a patch (d4042-1.diff) that makes the export and import procedures quote arguments correctly by using helper methods in IdUtil and StringUtil instead of just putting quotes around them. The patch also adds a test case to ImportExportTest (the test case is small, but the test diff is somewhat big because many helper methods had to be changed to allow another schema than APP to be used).

I have only run the tools test so far, but I will start the full regression suite soon.

I also believe there are some problems in ColumnInfo if the column names in the table to export/import contain double quotes, but I'll defer that to a followup patch.

Bryan Pendleton added a comment - 01/Feb/09 03:43 PM
The patch looks great, Knut. Thank goodness for IdUtil and StringUtil, they
are very useful. I had a little bit of struggle with the test, because I could see
where you added a test for quotes in schema name / table name (the IdUtil case),
but I couldn't see where you added a test for quotes in the file name (the StringUtil case).

Did I simply overlook that test?

Knut Anders Hatlen added a comment - 01/Feb/09 08:16 PM
Thanks for looking at the patch, Bryan!

There is only one added test case (testQuotesInArguments) and it actually does test quotes in the file name, although somewhat indirectly. The helper method doExport() exports a table to a file whose name is tableName + ".dat", and doImportAndVerify() imports a file with the same name. So since the table name contains both a single quote and a double quote, the name of the exported file should contain those characters too. It's probably worth a comment in the test case to make it clearer.

Bryan Pendleton added a comment - 01/Feb/09 08:28 PM
Thanks for the clarification. That seems fine to me. Yes, a comment in the test case would be worthwhile.

Knut Anders Hatlen added a comment - 01/Feb/09 08:48 PM
Added the following comment and committed revision 739830:

        // Create schema names and table names containing both single quotes
        // and double quotes to expose bugs both for internally generated
        // string literals (enclosed in single quotes) and SQL identifiers
        // (enclosed in double quotes). This will also indirectly test that
        // the export/import system procedures handle those characters in
        // file names (which they didn't do very well before the fix for
        // DERBY-4042), as doExport() and doImportAndVerify() use a file name
        // derived from the table name.

Myrna van Lunteren added a comment - 03/Feb/09 05:17 PM
It appears the commit caused failures on windows platforms, see for instance: http://dbtg.thresher.com/derby/test/Daily/jvm1.5/testing/Limited/testSummary-740039.html

Can you investigate?

Knut Anders Hatlen added a comment - 04/Feb/09 10:50 AM
I don't have a Windows box to test it on, but it looks like Windows isn't too happy with double quotes in file names. The bug only involved file names with single quotes, so I guess it would be fine to rewrite the test to test file names with single quotes only.

Knut Anders Hatlen added a comment - 04/Feb/09 11:22 AM
The attached patch changes the test so that it doesn't use a double quote in the file name. I haven't tested it on Windows, but I hope that this will make the test pass on that platform too.

Committed revision 740698.

Myrna van Lunteren added a comment - 04/Feb/09 11:39 AM
It passes for me on XP.
I was thinking maybe we could add some os-switching logic, but this is ok.

Chip Hartney added a comment - 04/Feb/09 01:53 PM
Windows does not all any of the following characters in file names: \ / : * ? " | < >

Addressing the apost is sufficient for me, at least.

Knut Anders Hatlen added a comment - 17/Mar/09 12:15 PM
Here's an attempt on a release note for this issue.