-
Igor Solodovnikov authored
In mysql_real_connect() when vio_socket_connect() fails we already have socket handle stored in net->vio. That means we should not explicitly call closesocket() at the end of the address list loop. If this is the last iteration of the loop then the code after the loop will pass control to the error label and end_server() call will close socket and free net->vio. If there will be another iteration of the loop then vio_reset() will be called with the new socket handle. Note that at the moment of vio_reset() call net->vio still owns the socket handle created on the previous iteration. So vio_reset() should close socket stored in net->vio and store the new socket there. Unfortunately vio_reset() did not close socket stored in Vio structure. This is why the patch makes following changes in vio_reset(): - If new socket handle passed to vio_reset() is not equal to the socket handle stored in Vio then socket handle will be closed before storing new value. If handles are equal then old socket is not closed. This is important for vio_reset() usage in ssl_do(). - If any error occurs then new vio_reset() implementation will not alter any Vio members thus preserving socket handle stored in Vio and not taking ownership over socket handle passed as parameter. With this behavior following code from mysql_real_connect() will be correct: > if (vio_reset(net->vio, VIO_TYPE_TCPIP, sock, NULL, flags)) > { > set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); > closesocket(sock); <--- close new handle > freeaddrinfo(res_lst); > if (client_bind_ai_lst) > freeaddrinfo(client_bind_ai_lst); > goto error; <--- close handle stored in net->vio > } If no error occurs then vio_reset() closes handle stored in net->vio and then stores new handle there. Otherwise explicit closesocket() call closes new handle and then control is passed to error label where end_server() closes old handle stored in net->vio. Reviewed-by:
Rafal Somla <rafal.somla@oracle.com> Reviewed-by:
Georgi Kodinov <georgi.kodinov@oracle.com> RB: 7973
Igor Solodovnikov authoredIn mysql_real_connect() when vio_socket_connect() fails we already have socket handle stored in net->vio. That means we should not explicitly call closesocket() at the end of the address list loop. If this is the last iteration of the loop then the code after the loop will pass control to the error label and end_server() call will close socket and free net->vio. If there will be another iteration of the loop then vio_reset() will be called with the new socket handle. Note that at the moment of vio_reset() call net->vio still owns the socket handle created on the previous iteration. So vio_reset() should close socket stored in net->vio and store the new socket there. Unfortunately vio_reset() did not close socket stored in Vio structure. This is why the patch makes following changes in vio_reset(): - If new socket handle passed to vio_reset() is not equal to the socket handle stored in Vio then socket handle will be closed before storing new value. If handles are equal then old socket is not closed. This is important for vio_reset() usage in ssl_do(). - If any error occurs then new vio_reset() implementation will not alter any Vio members thus preserving socket handle stored in Vio and not taking ownership over socket handle passed as parameter. With this behavior following code from mysql_real_connect() will be correct: > if (vio_reset(net->vio, VIO_TYPE_TCPIP, sock, NULL, flags)) > { > set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate); > closesocket(sock); <--- close new handle > freeaddrinfo(res_lst); > if (client_bind_ai_lst) > freeaddrinfo(client_bind_ai_lst); > goto error; <--- close handle stored in net->vio > } If no error occurs then vio_reset() closes handle stored in net->vio and then stores new handle there. Otherwise explicit closesocket() call closes new handle and then control is passed to error label where end_server() closes old handle stored in net->vio. Reviewed-by:
Rafal Somla <rafal.somla@oracle.com> Reviewed-by:
Georgi Kodinov <georgi.kodinov@oracle.com> RB: 7973
Loading