Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterized LIKE results in fail [DNET976] #895

Closed
firebird-automations opened this issue Nov 6, 2020 · 5 comments
Closed

Parameterized LIKE results in fail [DNET976] #895

firebird-automations opened this issue Nov 6, 2020 · 5 comments

Comments

@firebird-automations
Copy link

Submitted by: Marvin Klein (marvinklein)

Relate to CORE3559

Consider the following scenario.

Table: CUSTOMERS
Fields:
CUSTOMER_FIRSTNAME VARCHAR(10)
CUSTOMER_LASTNAME VARCHAR(15)

Now I have the follwing C#⁠ code

// Create connection
// Create Command
command.Parameters.AddWithValue("@SEARCH", $"%{search.ToUpper()}%");
command.CommandText = "SELECT * FROM CUSTOMERS WHERE CUSTOMER_FIRSTNAME LIKE @SEARCH OR CUSTOMER_LASTNAME LIKE @SEARCH";
command.ExecuteQuery(); // do something with the command. This works fine as long as my parameter search does not exceed 10 characters.

When you try this command with more than 10 characters, you get an exception. However, doing the following does not result in an exception:
command.CommandText = $"SELECT * FROM CUSTOMERS WHERE CUSTOMER_FIRSTNAME LIKE '%{search.ToUpper()}%' OR CUSTOMER_LASTNAME LIKE '%{search.ToUpper()}%' ";
command.ExecuteQuery(); // do something with the command, no exception

But using this way I am vulnerable to SQL-Injections.

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

Unfortunately this is a limitation in Firebird, see CORE3559. The workaround is to cast either the parameter or the column to a wider value. For example:

where customer_firstname like cast(@search as varchar(100))

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Link: This issue relate to CORE3559 [ CORE3559 ]

@firebird-automations
Copy link
Author

Modified by: @cincuranet

priority: Major [ 3 ] => Minor [ 4 ]

Component: http://ADO.NET Provider [ 10041 ]

Component: NuGet packages [ 10150 ] =>

@firebird-automations
Copy link
Author

Commented by: @cincuranet

As described by Mark, this is expected behavior.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants