Skip to content

Commit 4d5c8c9

Browse files
committed
Guard against short server scramble in sha256_password auth
mysqlnd_sha256_auth_get_auth_data() XORs SCRAMBLE_LENGTH bytes of the server-supplied scramble into the password without checking the scramble is at least that long, unlike the native and caching_sha2 plugins which reject a short scramble with CR_MALFORMED_PACKET. A server reporting a scramble shorter than 20 bytes shrinks the heap buffer the scramble is copied into, so the XOR reads past it. Add the same length guard the sibling plugins use.
1 parent d8e7418 commit 4d5c8c9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

ext/mysqlnd/mysqlnd_auth.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,11 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
908908
DBG_ENTER("mysqlnd_sha256_auth_get_auth_data");
909909
DBG_INF_FMT("salt(%zu)=[%.*s]", auth_plugin_data_len, (int) auth_plugin_data_len, auth_plugin_data);
910910

911+
if (auth_plugin_data_len < SCRAMBLE_LENGTH) {
912+
SET_CLIENT_ERROR(conn->error_info, CR_MALFORMED_PACKET, UNKNOWN_SQLSTATE, "The server sent wrong length for scramble");
913+
DBG_ERR_FMT("The server sent wrong length for scramble %zu. Expected %u", auth_plugin_data_len, SCRAMBLE_LENGTH);
914+
DBG_RETURN(NULL);
915+
}
911916

912917
if (conn->vio->data->ssl) {
913918
DBG_INF("simple clear text under SSL");

0 commit comments

Comments
 (0)