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

Fix MySQL reset packet with prepared statements #611

Merged
merged 3 commits into from
Dec 19, 2022

Conversation

Zhaars
Copy link
Contributor

@Zhaars Zhaars commented Dec 15, 2022

Fixed bug with MySQL PreparedStatements processing, add Reset packet handler. Add check on params number in Execute Statement.

PR is draft, as cossacklabs/ci-py-go-themis contains new mysql-pyhton-connector with CMySQLConnector. So we need to test it on the CI

Checklist

Fixed bug with mysql PS processing/add reset statement handler
@Zhaars Zhaars requested a review from Lagovas December 15, 2022 17:41
@@ -380,8 +380,11 @@ func (handler *Handler) ProxyClientConnection(ctx context.Context, errCh chan<-

handler.setQueryHandler(handler.QueryResponseHandler)
break
case CommandStatementClose, CommandStatementSendLongData, CommandStatementReset:
case CommandStatementClose, CommandStatementSendLongData:
clientLog.Debugln("Close|SendLongData|Reset command")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clientLog.Debugln("Close|SendLongData|Reset command")
clientLog.Debugln("Close|SendLongData command")

err := packet.SetParameters(newParameters)
if err != nil {
log.WithError(err).Error("Failed to update Bind packet")
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not send it as is because it is dangerous behavior. application expects that when it sent data out it will be protected and in safe in the database but acra will pass it as is if something fails on its side. Acra should not pass unprotected data to the database if it marked to be protected.

tests/test.py Outdated
if args is None:
args = []
with contextlib.closing(mysql.connector.connect(
use_unicode=False, raw=self.connection_args.raw, charset='ascii',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we don't use unicode and use charset ascii instead of utf8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can use Unicode. It affects how the non-binary string will be returned.

So then in _result_to_dict we don't need to do the following

 columns_name = [bytes(i[0], encoding='utf8').decode('utf8') for i in description]

but can just do (column will be passed in Unicode):

 columns_name = [i[0] for i in description]

Regarding the utf8 I tested but it fails, seems driver not supported that, I get the following on charset='utf8'

mysql.connector.errors.ProgrammingError: Character set '255' unsupported

@@ -4689,6 +4759,24 @@ def executePreparedStatement(self, query, args=None):
).execute_prepared_statement(query, args=args)


class TestMysqlConnectorCBinaryPreparedStatement(BasePrepareStatementMixin, BaseTestCase):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some comment with description what we expected this connector will do? it will help to understand at the future if this test will fail after updating driver or something else. and explain what we expected and should reproduce. because after a year if this test will fail, we will not remember what behavior we expected and what to do to back it again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Added error returning on GetBindParameters failure
@Zhaars Zhaars marked this pull request as ready for review December 16, 2022 15:37
@Zhaars Zhaars merged commit 0b47fca into master Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants