From b28c59a6cd089902e66a91e0d0974da34d1c922b Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Thu, 8 May 2025 22:01:25 +0300 Subject: Use 'void *' for arbitrary buffers, 'uint8 *' for byte arrays A 'void *' argument suggests that the caller might pass an arbitrary struct, which is appropriate for functions like libc's read/write, or pq_sendbytes(). 'uint8 *' is more appropriate for byte arrays that have no structure, like the cancellation keys or SCRAM tokens. Some places used 'char *', but 'uint8 *' is better because 'char *' is commonly used for null-terminated strings. Change code around SCRAM, MD5 authentication, and cancellation key handling to follow these conventions. Discussion: https://www.postgresql.org/message-id/61be9e31-7b7d-49d5-bc11-721800d89d64@eisentraut.org --- src/interfaces/libpq/fe-auth.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/interfaces/libpq/fe-auth.c') diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index ec7a9236044..84a042269de 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -798,7 +798,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq) int ret; char *crypt_pwd = NULL; const char *pwd_to_send; - char md5Salt[4]; + uint8 md5Salt[4]; /* Read the salt from the AuthenticationMD5Password message. */ if (areq == AUTH_REQ_MD5) @@ -829,7 +829,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq) } crypt_pwd2 = crypt_pwd + MD5_PASSWD_LEN + 1; - if (!pg_md5_encrypt(password, conn->pguser, + if (!pg_md5_encrypt(password, (uint8 *) conn->pguser, strlen(conn->pguser), crypt_pwd2, &errstr)) { @@ -1369,7 +1369,7 @@ PQencryptPassword(const char *passwd, const char *user) if (!crypt_pwd) return NULL; - if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr)) + if (!pg_md5_encrypt(passwd, (uint8 *) user, strlen(user), crypt_pwd, &errstr)) { free(crypt_pwd); return NULL; @@ -1482,7 +1482,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user, { const char *errstr = NULL; - if (!pg_md5_encrypt(passwd, user, strlen(user), crypt_pwd, &errstr)) + if (!pg_md5_encrypt(passwd, (uint8 *) user, strlen(user), crypt_pwd, &errstr)) { libpq_append_conn_error(conn, "could not encrypt password: %s", errstr); free(crypt_pwd); -- cgit v1.2.3