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/common/base64.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/common/base64.c') diff --git a/src/common/base64.c b/src/common/base64.c index 6028f413472..240461fe1e6 100644 --- a/src/common/base64.c +++ b/src/common/base64.c @@ -41,15 +41,15 @@ static const int8 b64lookup[128] = { /* * pg_b64_encode * - * Encode into base64 the given string. Returns the length of the encoded - * string, and -1 in the event of an error with the result buffer zeroed - * for safety. + * Encode the 'src' byte array into base64. Returns the length of the encoded + * string, and -1 in the event of an error with the result buffer zeroed for + * safety. */ int -pg_b64_encode(const char *src, int len, char *dst, int dstlen) +pg_b64_encode(const uint8 *src, int len, char *dst, int dstlen) { char *p; - const char *s, + const uint8 *s, *end = src + len; int pos = 2; uint32 buf = 0; @@ -59,7 +59,7 @@ pg_b64_encode(const char *src, int len, char *dst, int dstlen) while (s < end) { - buf |= (unsigned char) *s << (pos << 3); + buf |= *s << (pos << 3); pos--; s++; @@ -113,11 +113,11 @@ error: * buffer zeroed for safety. */ int -pg_b64_decode(const char *src, int len, char *dst, int dstlen) +pg_b64_decode(const char *src, int len, uint8 *dst, int dstlen) { const char *srcend = src + len, *s = src; - char *p = dst; + uint8 *p = dst; char c; int b = 0; uint32 buf = 0; -- cgit v1.2.3