Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb28c59a

Browse files
committed
Use 'void *' for arbitrary buffers, 'uint8 *' for byte arrays
A 'void *' argument suggests that the caller might pass an arbitrarystruct, which is appropriate for functions like libc's read/write, orpq_sendbytes(). 'uint8 *' is more appropriate for byte arrays thathave no structure, like the cancellation keys or SCRAM tokens. Someplaces used 'char *', but 'uint8 *' is better because 'char *' iscommonly used for null-terminated strings. Change code around SCRAM,MD5 authentication, and cancellation key handling to follow theseconventions.Discussion:https://www.postgresql.org/message-id/61be9e31-7b7d-49d5-bc11-721800d89d64@eisentraut.org
1 parent965213d commitb28c59a

File tree

24 files changed

+80
-80
lines changed

24 files changed

+80
-80
lines changed

‎contrib/dblink/dblink.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,7 +3218,7 @@ appendSCRAMKeysInfo(StringInfo buf)
32183218
len=pg_b64_enc_len(sizeof(MyProcPort->scram_ClientKey));
32193219
/* don't forget the zero-terminator */
32203220
client_key=palloc0(len+1);
3221-
encoded_len=pg_b64_encode((constchar*)MyProcPort->scram_ClientKey,
3221+
encoded_len=pg_b64_encode(MyProcPort->scram_ClientKey,
32223222
sizeof(MyProcPort->scram_ClientKey),
32233223
client_key,len);
32243224
if (encoded_len<0)
@@ -3227,7 +3227,7 @@ appendSCRAMKeysInfo(StringInfo buf)
32273227
len=pg_b64_enc_len(sizeof(MyProcPort->scram_ServerKey));
32283228
/* don't forget the zero-terminator */
32293229
server_key=palloc0(len+1);
3230-
encoded_len=pg_b64_encode((constchar*)MyProcPort->scram_ServerKey,
3230+
encoded_len=pg_b64_encode(MyProcPort->scram_ServerKey,
32313231
sizeof(MyProcPort->scram_ServerKey),
32323232
server_key,len);
32333233
if (encoded_len<0)

‎contrib/postgres_fdw/connection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
577577
len=pg_b64_enc_len(sizeof(MyProcPort->scram_ClientKey));
578578
/* don't forget the zero-terminator */
579579
values[n]=palloc0(len+1);
580-
encoded_len=pg_b64_encode((constchar*)MyProcPort->scram_ClientKey,
580+
encoded_len=pg_b64_encode(MyProcPort->scram_ClientKey,
581581
sizeof(MyProcPort->scram_ClientKey),
582582
(char*)values[n],len);
583583
if (encoded_len<0)
@@ -588,7 +588,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
588588
len=pg_b64_enc_len(sizeof(MyProcPort->scram_ServerKey));
589589
/* don't forget the zero-terminator */
590590
values[n]=palloc0(len+1);
591-
encoded_len=pg_b64_encode((constchar*)MyProcPort->scram_ServerKey,
591+
encoded_len=pg_b64_encode(MyProcPort->scram_ServerKey,
592592
sizeof(MyProcPort->scram_ServerKey),
593593
(char*)values[n],len);
594594
if (encoded_len<0)

‎src/backend/libpq/auth-scram.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ typedef struct
158158
/* Fields from the last message from client */
159159
char*client_final_message_without_proof;
160160
char*client_final_nonce;
161-
charClientProof[SCRAM_MAX_KEY_LEN];
161+
uint8ClientProof[SCRAM_MAX_KEY_LEN];
162162

163163
/* Fields generated in the server */
164164
char*server_first_message;
@@ -186,9 +186,9 @@ static void mock_scram_secret(const char *username, pg_cryptohash_type *hash_typ
186186
staticboolis_scram_printable(char*p);
187187
staticchar*sanitize_char(charc);
188188
staticchar*sanitize_str(constchar*s);
189-
staticchar*scram_mock_salt(constchar*username,
190-
pg_cryptohash_typehash_type,
191-
intkey_length);
189+
staticuint8*scram_mock_salt(constchar*username,
190+
pg_cryptohash_typehash_type,
191+
intkey_length);
192192

193193
/*
194194
* The number of iterations to use when generating new secrets.
@@ -484,7 +484,7 @@ pg_be_scram_build_secret(const char *password)
484484
{
485485
char*prep_password;
486486
pg_saslprep_rcrc;
487-
charsaltbuf[SCRAM_DEFAULT_SALT_LEN];
487+
uint8saltbuf[SCRAM_DEFAULT_SALT_LEN];
488488
char*result;
489489
constchar*errstr=NULL;
490490

@@ -524,7 +524,7 @@ scram_verify_plain_password(const char *username, const char *password,
524524
constchar*secret)
525525
{
526526
char*encoded_salt;
527-
char*salt;
527+
uint8*salt;
528528
intsaltlen;
529529
intiterations;
530530
intkey_length=0;
@@ -609,9 +609,9 @@ parse_scram_secret(const char *secret, int *iterations,
609609
char*storedkey_str;
610610
char*serverkey_str;
611611
intdecoded_len;
612-
char*decoded_salt_buf;
613-
char*decoded_stored_buf;
614-
char*decoded_server_buf;
612+
uint8*decoded_salt_buf;
613+
uint8*decoded_stored_buf;
614+
uint8*decoded_server_buf;
615615

616616
/*
617617
* The secret is of form:
@@ -698,7 +698,7 @@ mock_scram_secret(const char *username, pg_cryptohash_type *hash_type,
698698
int*iterations,int*key_length,char**salt,
699699
uint8*stored_key,uint8*server_key)
700700
{
701-
char*raw_salt;
701+
uint8*raw_salt;
702702
char*encoded_salt;
703703
intencoded_len;
704704

@@ -1231,7 +1231,7 @@ build_server_first_message(scram_state *state)
12311231
* For convenience, however, we don't use the whole range available,
12321232
* rather, we generate some random bytes, and base64 encode them.
12331233
*/
1234-
charraw_nonce[SCRAM_RAW_NONCE_LEN];
1234+
uint8raw_nonce[SCRAM_RAW_NONCE_LEN];
12351235
intencoded_len;
12361236

12371237
if (!pg_strong_random(raw_nonce,SCRAM_RAW_NONCE_LEN))
@@ -1271,7 +1271,7 @@ read_client_final_message(scram_state *state, const char *input)
12711271
char*begin,
12721272
*proof;
12731273
char*p;
1274-
char*client_proof;
1274+
uint8*client_proof;
12751275
intclient_proof_len;
12761276

12771277
begin=p=pstrdup(input);
@@ -1340,7 +1340,7 @@ read_client_final_message(scram_state *state, const char *input)
13401340
b64_message_len=pg_b64_enc_len(cbind_input_len);
13411341
/* don't forget the zero-terminator */
13421342
b64_message=palloc(b64_message_len+1);
1343-
b64_message_len=pg_b64_encode(cbind_input,cbind_input_len,
1343+
b64_message_len=pg_b64_encode((uint8*)cbind_input,cbind_input_len,
13441344
b64_message,b64_message_len);
13451345
if (b64_message_len<0)
13461346
elog(ERROR,"could not encode channel binding data");
@@ -1440,7 +1440,7 @@ build_server_final_message(scram_state *state)
14401440
siglen=pg_b64_enc_len(state->key_length);
14411441
/* don't forget the zero-terminator */
14421442
server_signature_base64=palloc(siglen+1);
1443-
siglen=pg_b64_encode((constchar*)ServerSignature,
1443+
siglen=pg_b64_encode(ServerSignature,
14441444
state->key_length,server_signature_base64,
14451445
siglen);
14461446
if (siglen<0)
@@ -1467,7 +1467,7 @@ build_server_final_message(scram_state *state)
14671467
* hash based on the username and a cluster-level secret key. Returns a
14681468
* pointer to a static buffer of size SCRAM_DEFAULT_SALT_LEN, or NULL.
14691469
*/
1470-
staticchar*
1470+
staticuint8*
14711471
scram_mock_salt(constchar*username,pg_cryptohash_typehash_type,
14721472
intkey_length)
14731473
{
@@ -1501,5 +1501,5 @@ scram_mock_salt(const char *username, pg_cryptohash_type hash_type,
15011501
}
15021502
pg_cryptohash_free(ctx);
15031503

1504-
return(char*)sha_digest;
1504+
returnsha_digest;
15051505
}

‎src/backend/libpq/auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ ClientAuthentication(Port *port)
666666
* Send an authentication request packet to the frontend.
667667
*/
668668
void
669-
sendAuthRequest(Port*port,AuthRequestareq,constchar*extradata,intextralen)
669+
sendAuthRequest(Port*port,AuthRequestareq,constvoid*extradata,intextralen)
670670
{
671671
StringInfoDatabuf;
672672

@@ -874,7 +874,7 @@ CheckPWChallengeAuth(Port *port, const char **logdetail)
874874
staticint
875875
CheckMD5Auth(Port*port,char*shadow_pass,constchar**logdetail)
876876
{
877-
charmd5Salt[4];/* Password salt */
877+
uint8md5Salt[4];/* Password salt */
878878
char*passwd;
879879
intresult;
880880

‎src/backend/libpq/crypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ encrypt_password(PasswordType target_type, const char *role,
136136
casePASSWORD_TYPE_MD5:
137137
encrypted_password=palloc(MD5_PASSWD_LEN+1);
138138

139-
if (!pg_md5_encrypt(password,role,strlen(role),
139+
if (!pg_md5_encrypt(password,(uint8*)role,strlen(role),
140140
encrypted_password,&errstr))
141141
elog(ERROR,"password encryption failed: %s",errstr);
142142
break;
@@ -201,7 +201,7 @@ encrypt_password(PasswordType target_type, const char *role,
201201
int
202202
md5_crypt_verify(constchar*role,constchar*shadow_pass,
203203
constchar*client_pass,
204-
constchar*md5_salt,intmd5_salt_len,
204+
constuint8*md5_salt,intmd5_salt_len,
205205
constchar**logdetail)
206206
{
207207
intretval;
@@ -284,7 +284,7 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
284284

285285
casePASSWORD_TYPE_MD5:
286286
if (!pg_md5_encrypt(client_pass,
287-
role,
287+
(uint8*)role,
288288
strlen(role),
289289
crypt_client_pass,
290290
&errstr))

‎src/backend/storage/ipc/procsignal.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef struct
6464
{
6565
pg_atomic_uint32pss_pid;
6666
intpss_cancel_key_len;/* 0 means no cancellation is possible */
67-
charpss_cancel_key[MAX_CANCEL_KEY_LENGTH];
67+
uint8pss_cancel_key[MAX_CANCEL_KEY_LENGTH];
6868
volatilesig_atomic_tpss_signalFlags[NUM_PROCSIGNALS];
6969
slock_tpss_mutex;/* protects the above fields */
7070

@@ -163,7 +163,7 @@ ProcSignalShmemInit(void)
163163
*Register the current process in the ProcSignal array
164164
*/
165165
void
166-
ProcSignalInit(char*cancel_key,intcancel_key_len)
166+
ProcSignalInit(constuint8*cancel_key,intcancel_key_len)
167167
{
168168
ProcSignalSlot*slot;
169169
uint64barrier_generation;
@@ -729,7 +729,7 @@ procsignal_sigusr1_handler(SIGNAL_ARGS)
729729
* fields in the ProcSignal slots.
730730
*/
731731
void
732-
SendCancelRequest(intbackendPID,char*cancel_key,intcancel_key_len)
732+
SendCancelRequest(intbackendPID,constuint8*cancel_key,intcancel_key_len)
733733
{
734734
Assert(backendPID!=0);
735735

‎src/backend/utils/init/globals.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pg_time_tMyStartTime;
5050
TimestampTzMyStartTimestamp;
5151
structClientSocket*MyClientSocket;
5252
structPort*MyProcPort;
53-
charMyCancelKey[MAX_CANCEL_KEY_LENGTH];
53+
uint8MyCancelKey[MAX_CANCEL_KEY_LENGTH];
5454
intMyCancelKeyLength=0;
5555
intMyPMChildSlot;
5656

‎src/common/base64.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ static const int8 b64lookup[128] = {
4141
/*
4242
* pg_b64_encode
4343
*
44-
* Encodeinto base64 the given string. Returns the length of the encoded
45-
* string, and -1 in the event of an error with the result buffer zeroed
46-
*forsafety.
44+
* Encodethe 'src' byte array into base64. Returns the length of the encoded
45+
* string, and -1 in the event of an error with the result buffer zeroed for
46+
* safety.
4747
*/
4848
int
49-
pg_b64_encode(constchar*src,intlen,char*dst,intdstlen)
49+
pg_b64_encode(constuint8*src,intlen,char*dst,intdstlen)
5050
{
5151
char*p;
52-
constchar*s,
52+
constuint8*s,
5353
*end=src+len;
5454
intpos=2;
5555
uint32buf=0;
@@ -59,7 +59,7 @@ pg_b64_encode(const char *src, int len, char *dst, int dstlen)
5959

6060
while (s<end)
6161
{
62-
buf |=(unsignedchar)*s << (pos <<3);
62+
buf |=*s << (pos <<3);
6363
pos--;
6464
s++;
6565

@@ -113,11 +113,11 @@ pg_b64_encode(const char *src, int len, char *dst, int dstlen)
113113
* buffer zeroed for safety.
114114
*/
115115
int
116-
pg_b64_decode(constchar*src,intlen,char*dst,intdstlen)
116+
pg_b64_decode(constchar*src,intlen,uint8*dst,intdstlen)
117117
{
118118
constchar*srcend=src+len,
119119
*s=src;
120-
char*p=dst;
120+
uint8*p=dst;
121121
charc;
122122
intb=0;
123123
uint32buf=0;

‎src/common/md5_common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pg_md5_hash(const void *buff, size_t len, char *hexsum, const char **errstr)
105105
* (of size MD5_DIGEST_LENGTH) rather than being converted to ASCII hex.
106106
*/
107107
bool
108-
pg_md5_binary(constvoid*buff,size_tlen,void*outbuf,constchar**errstr)
108+
pg_md5_binary(constvoid*buff,size_tlen,uint8*outbuf,constchar**errstr)
109109
{
110110
pg_cryptohash_ctx*ctx;
111111

@@ -142,7 +142,7 @@ pg_md5_binary(const void *buff, size_t len, void *outbuf, const char **errstr)
142142
* error context.
143143
*/
144144
bool
145-
pg_md5_encrypt(constchar*passwd,constchar*salt,size_tsalt_len,
145+
pg_md5_encrypt(constchar*passwd,constuint8*salt,size_tsalt_len,
146146
char*buf,constchar**errstr)
147147
{
148148
size_tpasswd_len=strlen(passwd);

‎src/common/scram-common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
int
3838
scram_SaltedPassword(constchar*password,
3939
pg_cryptohash_typehash_type,intkey_length,
40-
constchar*salt,intsaltlen,intiterations,
40+
constuint8*salt,intsaltlen,intiterations,
4141
uint8*result,constchar**errstr)
4242
{
4343
intpassword_len=strlen(password);
@@ -62,7 +62,7 @@ scram_SaltedPassword(const char *password,
6262

6363
/* First iteration */
6464
if (pg_hmac_init(hmac_ctx, (uint8*)password,password_len)<0||
65-
pg_hmac_update(hmac_ctx,(uint8*)salt,saltlen)<0||
65+
pg_hmac_update(hmac_ctx,salt,saltlen)<0||
6666
pg_hmac_update(hmac_ctx, (uint8*)&one,sizeof(uint32))<0||
6767
pg_hmac_final(hmac_ctx,Ui_prev,key_length)<0)
6868
{
@@ -207,7 +207,7 @@ scram_ServerKey(const uint8 *salted_password,
207207
*/
208208
char*
209209
scram_build_secret(pg_cryptohash_typehash_type,intkey_length,
210-
constchar*salt,intsaltlen,intiterations,
210+
constuint8*salt,intsaltlen,intiterations,
211211
constchar*password,constchar**errstr)
212212
{
213213
uint8salted_password[SCRAM_MAX_KEY_LEN];
@@ -290,7 +290,7 @@ scram_build_secret(pg_cryptohash_type hash_type, int key_length,
290290
*(p++)='$';
291291

292292
/* stored key */
293-
encoded_result=pg_b64_encode((char*)stored_key,key_length,p,
293+
encoded_result=pg_b64_encode(stored_key,key_length,p,
294294
encoded_stored_len);
295295
if (encoded_result<0)
296296
{
@@ -307,7 +307,7 @@ scram_build_secret(pg_cryptohash_type hash_type, int key_length,
307307
*(p++)=':';
308308

309309
/* server key */
310-
encoded_result=pg_b64_encode((char*)server_key,key_length,p,
310+
encoded_result=pg_b64_encode(server_key,key_length,p,
311311
encoded_server_len);
312312
if (encoded_result<0)
313313
{

‎src/include/common/base64.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#defineBASE64_H
1212

1313
/* base 64 */
14-
pg_nodiscardexternintpg_b64_encode(constchar*src,intlen,char*dst,intdstlen);
15-
pg_nodiscardexternintpg_b64_decode(constchar*src,intlen,char*dst,intdstlen);
14+
pg_nodiscardexternintpg_b64_encode(constuint8*src,intlen,char*dst,intdstlen);
15+
pg_nodiscardexternintpg_b64_decode(constchar*src,intlen,uint8*dst,intdstlen);
1616
externintpg_b64_enc_len(intsrclen);
1717
externintpg_b64_dec_len(intsrclen);
1818

‎src/include/common/md5.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
/* Utilities common to all the MD5 implementations, as of md5_common.c */
2929
externboolpg_md5_hash(constvoid*buff,size_tlen,char*hexsum,
3030
constchar**errstr);
31-
externboolpg_md5_binary(constvoid*buff,size_tlen,void*outbuf,
31+
externboolpg_md5_binary(constvoid*buff,size_tlen,uint8*outbuf,
3232
constchar**errstr);
33-
externboolpg_md5_encrypt(constchar*passwd,constchar*salt,
33+
externboolpg_md5_encrypt(constchar*passwd,constuint8*salt,
3434
size_tsalt_len,char*buf,
3535
constchar**errstr);
3636

‎src/include/common/scram-common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
externintscram_SaltedPassword(constchar*password,
5353
pg_cryptohash_typehash_type,intkey_length,
54-
constchar*salt,intsaltlen,intiterations,
54+
constuint8*salt,intsaltlen,intiterations,
5555
uint8*result,constchar**errstr);
5656
externintscram_H(constuint8*input,pg_cryptohash_typehash_type,
5757
intkey_length,uint8*result,
@@ -64,7 +64,7 @@ extern intscram_ServerKey(const uint8 *salted_password,
6464
uint8*result,constchar**errstr);
6565

6666
externchar*scram_build_secret(pg_cryptohash_typehash_type,intkey_length,
67-
constchar*salt,intsaltlen,intiterations,
67+
constuint8*salt,intsaltlen,intiterations,
6868
constchar*password,constchar**errstr);
6969

7070
#endif/* SCRAM_COMMON_H */

‎src/include/libpq/auth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern PGDLLIMPORT bool pg_krb_caseins_users;
3737
externPGDLLIMPORTboolpg_gss_accept_delegation;
3838

3939
externvoidClientAuthentication(Port*port);
40-
externvoidsendAuthRequest(Port*port,AuthRequestareq,constchar*extradata,
40+
externvoidsendAuthRequest(Port*port,AuthRequestareq,constvoid*extradata,
4141
intextralen);
4242
externvoidset_authn_id(Port*port,constchar*id);
4343

‎src/include/libpq/crypt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern char *encrypt_password(PasswordType target_type, const char *role,
5151
externchar*get_role_password(constchar*role,constchar**logdetail);
5252

5353
externintmd5_crypt_verify(constchar*role,constchar*shadow_pass,
54-
constchar*client_pass,constchar*md5_salt,
54+
constchar*client_pass,constuint8*md5_salt,
5555
intmd5_salt_len,constchar**logdetail);
5656
externintplain_crypt_verify(constchar*role,constchar*shadow_pass,
5757
constchar*client_pass,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp