-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement mysqlnd_set_persistent_string #7371
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,10 +99,7 @@ mysqlnd_run_authentication( | |
switch_to_auth_protocol = NULL; | ||
switch_to_auth_protocol_len = 0; | ||
|
||
if (conn->authentication_plugin_data.s) { | ||
mnd_pefree(conn->authentication_plugin_data.s, conn->persistent); | ||
conn->authentication_plugin_data.s = NULL; | ||
} | ||
mysqlnd_set_persistent_string(&conn->authentication_plugin_data, NULL, 0, conn->persistent); | ||
conn->authentication_plugin_data.l = plugin_data_len; | ||
conn->authentication_plugin_data.s = mnd_pemalloc(conn->authentication_plugin_data.l, conn->persistent); | ||
memcpy(conn->authentication_plugin_data.s, plugin_data, plugin_data_len); | ||
|
@@ -490,24 +487,16 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn, | |
} | ||
} | ||
if (ret == PASS) { | ||
char * tmp = NULL; | ||
/* if we get conn->username as parameter and then we first free it, then estrndup it, we will crash */ | ||
nikic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tmp = mnd_pestrndup(user, user_len, conn->persistent); | ||
if (conn->username.s) { | ||
mnd_pefree(conn->username.s, conn->persistent); | ||
} | ||
conn->username.s = tmp; | ||
ZEND_ASSERT(conn->username.s != user && conn->password.s != passwd); | ||
mysqlnd_set_persistent_string(&conn->username, user, user_len, conn->persistent); | ||
|
||
tmp = mnd_pestrdup(passwd, conn->persistent); | ||
char * tmp = mnd_pestrdup(passwd, conn->persistent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the conn->password assignment be changed as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the non-N version. I wasn't sure if I can touch this given that it is a variable-length assignment and the previous code didn't set the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pestrdup = pestrndup + strlen basically. You make a good point on this not assigning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed there is I grepped for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Let's land this patch first and then remove them. I could see how they might be useful for a hypothetical "automatic reconnect" functionality, but given how such a functionality doesn't exist... |
||
if (conn->password.s) { | ||
mnd_pefree(conn->password.s, conn->persistent); | ||
} | ||
conn->password.s = tmp; | ||
|
||
if (conn->last_message.s) { | ||
mnd_efree(conn->last_message.s); | ||
conn->last_message.s = NULL; | ||
} | ||
mysqlnd_set_string(&conn->last_message, NULL, 0); | ||
UPSERT_STATUS_RESET(conn->upsert_status); | ||
/* set charset for old servers */ | ||
if (conn->m->get_server_version(conn) < 50123) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure If I can change this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pemalloc+memcpy is the same as pestrndup, so changing this should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tried it but I get warnings because it is
zend_uchar
. I am not sure what is going on with this assignment so I will roll back this one change.