MySQL 26.10.0
Source Code Documentation
get_password.cc File Reference
#include "my_config.h"
#include "m_string.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include <pwd.h>

Functions

char * get_tty_password (const char *opt_message)
 Read a password from the terminal without echoing the typed characters. More...
 

Function Documentation

◆ get_tty_password()

char * get_tty_password ( const char *  opt_message)

Read a password from the terminal without echoing the typed characters.

Displays opt_message (or the default prompt "Enter password: ") and reads characters one by one until the user presses Enter, Ctrl-C, or until the internal buffer is exhausted. The returned string is allocated with my_strdup() (MY_FAE flag); the caller must release it with my_free().

Parameters
opt_messagePrompt to display before reading. Pass NULL to use the default "Enter password: ".
Returns
Heap-allocated, NUL-terminated password string.
Note
Bug#44929 / Bug#92403 / Bug#110570 The internal stack buffer was historically 80 bytes, which silently truncated any password longer than 79 characters; the NUL terminator consumed the 80th slot and all further input was discarded without warning. This caused authentication failures for high-entropy passwords and made it impossible to use long authentication credentials (such as OAuth/OIDC access tokens, which routinely exceed 2000 bytes) through the interactive prompt.

Two concrete scenarios exposed this defect:

(1) Long passwords. Some deployments (notably managed cloud MySQL services) permit account passwords of 128 characters or more. Users who chose a password of 80 characters or more could create the account successfully, but every subsequent attempt to authenticate with mysql -p would silently strip the password to 79 characters before sending it to the server, producing an "Access denied" error with no indication that truncation had occurred.

(2) Token-based authentication. Authentication plugins such as mysql_clear_password are commonly used to forward externally issued bearer tokens (for example OAuth 2.0 / OIDC access tokens) as the password field. Such tokens routinely exceed 2000 characters (a typical JWT bearer token is ~2400 characters). Users who preferred the interactive workflow — running mysql -p and then pasting the token at the "Enter password:" prompt — were unable to authenticate because the token was silently truncated to 79 characters. The resulting "Access denied" error gave no hint that the credential had been cut short, making the problem difficult to diagnose.

In both cases the only viable workaround was to pass the credential inline as -p<value> (no space), which bypasses get_tty_password() entirely. However that approach exposes the password or token in the operating-system process list and the shell command history, which is unacceptable in security- conscious environments.

The buffer has been enlarged to 4096 bytes. Passwords and tokens up to 4095 characters can now be entered interactively. The downstream path — opt_password[], mysql->passwd, and clear_password_auth_client() — imposes no additional length restriction, so the full credential is transmitted to the server.