Skip to content

Fix mysqlnd protocol errors #16421

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

kamil-tekiela
Copy link
Member

The warnings are removed similarly to what was done in 2856afc

mysqlnd should have been raising client errors when the packet is malformed. In all places where it is possible without refactoring, I have changed the warnings to client errors. I have tested most of them to see if they are properly propagated.

There are still more places where warnings need to be converted into client errors.

@cmb69
Copy link
Member

cmb69 commented Oct 13, 2024

Does this "match" libmysql-client behavior? I'm asking wrt PDO_MySQL which still may use either.

@kamil-tekiela
Copy link
Member Author

Does this "match" libmysql-client behavior? I'm asking wrt PDO_MySQL which still may use either.

It's an implementation detail so I don't think it matters. I am not even sure if we can compare them like that. Obviously, libmysql can't raise PHP E_WARNINGs so this PR might bring their behaviour more aligned.

Libmysql raises client errors in similar situations too https://github.com/mysql/mysql-server/blob/trunk/libmysql/libmysql.cc#L3984 It's the intended way for clients (either libmysql or mysqlnd) to raise errors specific to their implementation.

@@ -863,9 +859,7 @@ php_mysqlnd_ok_read(MYSQLND_CONN_DATA * conn, void * _packet)

DBG_RETURN(PASS);
premature_end:
DBG_ERR_FMT("OK packet %zu bytes shorter than expected", p - begin - packet->header.size);
Copy link
Member

Choose a reason for hiding this comment

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

why are you getting rid of all DBG_ERR_FMT?

Copy link
Member

Choose a reason for hiding this comment

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

I guess that they will get logged from error (haven't checked though) but that bytes info can be useful there in some cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not all, just a couple that I saw now. Why are you asking? Are you using them? I think we should remove all of them, but it's a lot of work and since it's dead code, there's little harm in keeping them in the code. If someone ever needs to debug this piece of code, and they use this debug feature, they can add these lines themselves.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case people don't know. DBG_ERR_FMT is a macro that can be enabled with some compiler option and when it is on, mysqlnd will spew out debugging information to CLI. If it's off, then the compiler simply discards these lines.

@kamil-tekiela kamil-tekiela marked this pull request as draft October 13, 2024 19:44
@kamil-tekiela kamil-tekiela force-pushed the Fix-mysqlnd-protocol-errors branch from 6412634 to 11a272f Compare November 21, 2024 22:59
@kamil-tekiela kamil-tekiela marked this pull request as ready for review November 21, 2024 22:59
@kamil-tekiela kamil-tekiela force-pushed the Fix-mysqlnd-protocol-errors branch from 11a272f to 240d885 Compare November 21, 2024 23:16
@kamil-tekiela
Copy link
Member Author

@bukka I have changed 3 more warnings from your recent PR. Is this PR ok now?

Copy link
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

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

It would be really good to add tests for all those changed cases that are not covered. It could show some possible issues as well - it could show some issues as those paths are often not really tested.

@kamil-tekiela
Copy link
Member Author

It would be really good to add tests for all those changed cases that are not covered. It could show some possible issues as well - it could show some issues as those paths are often not really tested.

I will try, but it may be very difficult. I don't know how to trigger many of these errors or whether it's even possible.

@bukka
Copy link
Member

bukka commented Nov 24, 2024

Sure, ping me once you are done I will take a look if I maybe get an idea how to cover some of the missing ones. It's not a big deal if the difficult ones are not covered.

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

Successfully merging this pull request may close these issues.

3 participants