Skip to content

Add Windows support for caching_sha2_password #5129

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions ext/mysqlnd/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ if (PHP_MYSQLND != "no") {
{
AC_DEFINE("MYSQLND_COMPRESSION_ENABLED", 1, "Compression support");
AC_DEFINE("MYSQLND_SSL_SUPPORTED", 1, "SSL support");
if (SETUP_OPENSSL("mysqlnd", PHP_MYSQLND) >= 0) {
AC_DEFINE("MYSQLND_HAVE_SSL", 1, "Extended SSL support");
}
}
PHP_INSTALL_HEADERS("", "ext/mysqlnd");
}
Expand Down
8 changes: 6 additions & 2 deletions ext/mysqlnd/mysqlnd_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,8 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self

if (server_public_key) {
int server_public_key_len;
char xor_str[passwd_len + 1];
ALLOCA_FLAG(use_heap)
char *xor_str = do_alloca(passwd_len + 1, use_heap);
memcpy(xor_str, passwd, passwd_len);
xor_str[passwd_len] = '\0';
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, auth_plugin_data_len);
Expand All @@ -828,6 +829,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
ret = malloc(*auth_data_len);
RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, ret, server_public_key, RSA_PKCS1_OAEP_PADDING);
RSA_free(server_public_key);
free_alloca(xor_str, use_heap);
}
}

Expand Down Expand Up @@ -1025,7 +1027,8 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,

if (server_public_key) {
int server_public_key_len;
char xor_str[passwd_len + 1];
ALLOCA_FLAG(use_heap)
char *xor_str = do_alloca(passwd_len + 1, use_heap);
memcpy(xor_str, passwd, passwd_len);
xor_str[passwd_len] = '\0';
mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, SCRAMBLE_LENGTH);
Expand All @@ -1045,6 +1048,7 @@ mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn,

*crypted = emalloc(server_public_key_len);
RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, *crypted, server_public_key, RSA_PKCS1_OAEP_PADDING);
free_alloca(xor_str, use_heap);
DBG_RETURN(server_public_key_len);
}
DBG_RETURN(0);
Expand Down
7 changes: 0 additions & 7 deletions ext/mysqlnd/mysqlnd_wireprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -2141,12 +2141,8 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
#if HAVE_COMPILER_C99_VLA
zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1];
#else
ALLOCA_FLAG(use_heap)
zend_uchar *buffer = do_alloca(MYSQLND_HEADER_SIZE + packet->password_len + 1, use_heap);
#endif
size_t sent;

DBG_ENTER("php_mysqlnd_cached_sha2_result_write");
Expand All @@ -2158,10 +2154,7 @@ size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _pa
memcpy(buffer + MYSQLND_HEADER_SIZE, packet->password, packet->password_len);
sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info);
}

#if !HAVE_COMPILER_C99_VLA
free_alloca(buffer, use_heap);
#endif

DBG_RETURN(sent);
}
Expand Down