mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
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
This commit is contained in:
@@ -158,7 +158,7 @@ typedef struct
|
||||
/* Fields from the last message from client */
|
||||
char *client_final_message_without_proof;
|
||||
char *client_final_nonce;
|
||||
char ClientProof[SCRAM_MAX_KEY_LEN];
|
||||
uint8 ClientProof[SCRAM_MAX_KEY_LEN];
|
||||
|
||||
/* Fields generated in the server */
|
||||
char *server_first_message;
|
||||
@@ -186,9 +186,9 @@ static void mock_scram_secret(const char *username, pg_cryptohash_type *hash_typ
|
||||
static bool is_scram_printable(char *p);
|
||||
static char *sanitize_char(char c);
|
||||
static char *sanitize_str(const char *s);
|
||||
static char *scram_mock_salt(const char *username,
|
||||
pg_cryptohash_type hash_type,
|
||||
int key_length);
|
||||
static uint8 *scram_mock_salt(const char *username,
|
||||
pg_cryptohash_type hash_type,
|
||||
int key_length);
|
||||
|
||||
/*
|
||||
* The number of iterations to use when generating new secrets.
|
||||
@@ -484,7 +484,7 @@ pg_be_scram_build_secret(const char *password)
|
||||
{
|
||||
char *prep_password;
|
||||
pg_saslprep_rc rc;
|
||||
char saltbuf[SCRAM_DEFAULT_SALT_LEN];
|
||||
uint8 saltbuf[SCRAM_DEFAULT_SALT_LEN];
|
||||
char *result;
|
||||
const char *errstr = NULL;
|
||||
|
||||
@@ -524,7 +524,7 @@ scram_verify_plain_password(const char *username, const char *password,
|
||||
const char *secret)
|
||||
{
|
||||
char *encoded_salt;
|
||||
char *salt;
|
||||
uint8 *salt;
|
||||
int saltlen;
|
||||
int iterations;
|
||||
int key_length = 0;
|
||||
@@ -609,9 +609,9 @@ parse_scram_secret(const char *secret, int *iterations,
|
||||
char *storedkey_str;
|
||||
char *serverkey_str;
|
||||
int decoded_len;
|
||||
char *decoded_salt_buf;
|
||||
char *decoded_stored_buf;
|
||||
char *decoded_server_buf;
|
||||
uint8 *decoded_salt_buf;
|
||||
uint8 *decoded_stored_buf;
|
||||
uint8 *decoded_server_buf;
|
||||
|
||||
/*
|
||||
* The secret is of form:
|
||||
@@ -698,7 +698,7 @@ mock_scram_secret(const char *username, pg_cryptohash_type *hash_type,
|
||||
int *iterations, int *key_length, char **salt,
|
||||
uint8 *stored_key, uint8 *server_key)
|
||||
{
|
||||
char *raw_salt;
|
||||
uint8 *raw_salt;
|
||||
char *encoded_salt;
|
||||
int encoded_len;
|
||||
|
||||
@@ -1231,7 +1231,7 @@ build_server_first_message(scram_state *state)
|
||||
* For convenience, however, we don't use the whole range available,
|
||||
* rather, we generate some random bytes, and base64 encode them.
|
||||
*/
|
||||
char raw_nonce[SCRAM_RAW_NONCE_LEN];
|
||||
uint8 raw_nonce[SCRAM_RAW_NONCE_LEN];
|
||||
int encoded_len;
|
||||
|
||||
if (!pg_strong_random(raw_nonce, SCRAM_RAW_NONCE_LEN))
|
||||
@@ -1271,7 +1271,7 @@ read_client_final_message(scram_state *state, const char *input)
|
||||
char *begin,
|
||||
*proof;
|
||||
char *p;
|
||||
char *client_proof;
|
||||
uint8 *client_proof;
|
||||
int client_proof_len;
|
||||
|
||||
begin = p = pstrdup(input);
|
||||
@@ -1340,7 +1340,7 @@ read_client_final_message(scram_state *state, const char *input)
|
||||
b64_message_len = pg_b64_enc_len(cbind_input_len);
|
||||
/* don't forget the zero-terminator */
|
||||
b64_message = palloc(b64_message_len + 1);
|
||||
b64_message_len = pg_b64_encode(cbind_input, cbind_input_len,
|
||||
b64_message_len = pg_b64_encode((uint8 *) cbind_input, cbind_input_len,
|
||||
b64_message, b64_message_len);
|
||||
if (b64_message_len < 0)
|
||||
elog(ERROR, "could not encode channel binding data");
|
||||
@@ -1440,7 +1440,7 @@ build_server_final_message(scram_state *state)
|
||||
siglen = pg_b64_enc_len(state->key_length);
|
||||
/* don't forget the zero-terminator */
|
||||
server_signature_base64 = palloc(siglen + 1);
|
||||
siglen = pg_b64_encode((const char *) ServerSignature,
|
||||
siglen = pg_b64_encode(ServerSignature,
|
||||
state->key_length, server_signature_base64,
|
||||
siglen);
|
||||
if (siglen < 0)
|
||||
@@ -1467,7 +1467,7 @@ build_server_final_message(scram_state *state)
|
||||
* hash based on the username and a cluster-level secret key. Returns a
|
||||
* pointer to a static buffer of size SCRAM_DEFAULT_SALT_LEN, or NULL.
|
||||
*/
|
||||
static char *
|
||||
static uint8 *
|
||||
scram_mock_salt(const char *username, pg_cryptohash_type hash_type,
|
||||
int key_length)
|
||||
{
|
||||
@@ -1501,5 +1501,5 @@ scram_mock_salt(const char *username, pg_cryptohash_type hash_type,
|
||||
}
|
||||
pg_cryptohash_free(ctx);
|
||||
|
||||
return (char *) sha_digest;
|
||||
return sha_digest;
|
||||
}
|
||||
|
||||
@@ -666,7 +666,7 @@ ClientAuthentication(Port *port)
|
||||
* Send an authentication request packet to the frontend.
|
||||
*/
|
||||
void
|
||||
sendAuthRequest(Port *port, AuthRequest areq, const char *extradata, int extralen)
|
||||
sendAuthRequest(Port *port, AuthRequest areq, const void *extradata, int extralen)
|
||||
{
|
||||
StringInfoData buf;
|
||||
|
||||
@@ -874,7 +874,7 @@ CheckPWChallengeAuth(Port *port, const char **logdetail)
|
||||
static int
|
||||
CheckMD5Auth(Port *port, char *shadow_pass, const char **logdetail)
|
||||
{
|
||||
char md5Salt[4]; /* Password salt */
|
||||
uint8 md5Salt[4]; /* Password salt */
|
||||
char *passwd;
|
||||
int result;
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ encrypt_password(PasswordType target_type, const char *role,
|
||||
case PASSWORD_TYPE_MD5:
|
||||
encrypted_password = palloc(MD5_PASSWD_LEN + 1);
|
||||
|
||||
if (!pg_md5_encrypt(password, role, strlen(role),
|
||||
if (!pg_md5_encrypt(password, (uint8 *) role, strlen(role),
|
||||
encrypted_password, &errstr))
|
||||
elog(ERROR, "password encryption failed: %s", errstr);
|
||||
break;
|
||||
@@ -201,7 +201,7 @@ encrypt_password(PasswordType target_type, const char *role,
|
||||
int
|
||||
md5_crypt_verify(const char *role, const char *shadow_pass,
|
||||
const char *client_pass,
|
||||
const char *md5_salt, int md5_salt_len,
|
||||
const uint8 *md5_salt, int md5_salt_len,
|
||||
const char **logdetail)
|
||||
{
|
||||
int retval;
|
||||
@@ -284,7 +284,7 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
|
||||
|
||||
case PASSWORD_TYPE_MD5:
|
||||
if (!pg_md5_encrypt(client_pass,
|
||||
role,
|
||||
(uint8 *) role,
|
||||
strlen(role),
|
||||
crypt_client_pass,
|
||||
&errstr))
|
||||
|
||||
@@ -64,7 +64,7 @@ typedef struct
|
||||
{
|
||||
pg_atomic_uint32 pss_pid;
|
||||
int pss_cancel_key_len; /* 0 means no cancellation is possible */
|
||||
char pss_cancel_key[MAX_CANCEL_KEY_LENGTH];
|
||||
uint8 pss_cancel_key[MAX_CANCEL_KEY_LENGTH];
|
||||
volatile sig_atomic_t pss_signalFlags[NUM_PROCSIGNALS];
|
||||
slock_t pss_mutex; /* protects the above fields */
|
||||
|
||||
@@ -163,7 +163,7 @@ ProcSignalShmemInit(void)
|
||||
* Register the current process in the ProcSignal array
|
||||
*/
|
||||
void
|
||||
ProcSignalInit(char *cancel_key, int cancel_key_len)
|
||||
ProcSignalInit(const uint8 *cancel_key, int cancel_key_len)
|
||||
{
|
||||
ProcSignalSlot *slot;
|
||||
uint64 barrier_generation;
|
||||
@@ -729,7 +729,7 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
|
||||
* fields in the ProcSignal slots.
|
||||
*/
|
||||
void
|
||||
SendCancelRequest(int backendPID, char *cancel_key, int cancel_key_len)
|
||||
SendCancelRequest(int backendPID, const uint8 *cancel_key, int cancel_key_len)
|
||||
{
|
||||
Assert(backendPID != 0);
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ pg_time_t MyStartTime;
|
||||
TimestampTz MyStartTimestamp;
|
||||
struct ClientSocket *MyClientSocket;
|
||||
struct Port *MyProcPort;
|
||||
char MyCancelKey[MAX_CANCEL_KEY_LENGTH];
|
||||
uint8 MyCancelKey[MAX_CANCEL_KEY_LENGTH];
|
||||
int MyCancelKeyLength = 0;
|
||||
int MyPMChildSlot;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user