Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5206,6 +5206,7 @@ int MySQL_Session::handler() {
NEXT_IMMEDIATE(CONNECTING_SERVER);
return handler_ret;
}
myconn = myds->myconn;
handler_minus1_GenerateErrorMessage(myds, myconn, wrong_pass);
RequestEnd(myds, myerr);
handler_minus1_HandleBackendConnection(myds, myconn);
Comment on lines +5209 to 5212

Choose a reason for hiding this comment

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

medium

Your fix is correct and effectively prevents the use-after-free bug.

However, to make the code more robust and prevent similar issues in the future, we could consider a small refactoring. The functions handler_minus1_GenerateErrorMessage and handler_minus1_HandleBackendConnection are passed a myconn pointer that might be stale.

Instead of passing myconn, these functions could retrieve the connection pointer directly from the MySQL_Data_Stream (myds) argument they already receive. This would ensure they always work with the most up-to-date connection state.

For example, handler_minus1_GenerateErrorMessage could be changed like this:

// from
void MySQL_Session::handler_minus1_GenerateErrorMessage(MySQL_Data_Stream *myds, MySQL_Connection *myconn, bool& wrong_pass) {
    // ...
}

// to
void MySQL_Session::handler_minus1_GenerateErrorMessage(MySQL_Data_Stream *myds, bool& wrong_pass) {
    MySQL_Connection *myconn = myds->myconn;
    // ...
}

A similar change could be applied to handler_minus1_HandleBackendConnection.

This would eliminate the need for the myconn = myds->myconn; line here and make the data flow clearer. What do you think?

Expand Down