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

Commitfa87870

Browse files
committed
Refactor RandomSalt to handle salts of different lengths.
All we need is 4 bytes at the moment, for MD5 authentication. But inupcomint patches for SCRAM authentication, SCRAM will need a salt ofdifferent length. It's less scary for the caller to pass the bufferlength anyway, than assume a certain-sized output buffer.Author: Michael PaquierDiscussion: <CAB7nPqQvO4sxLFeS9D+NM3wpy08ieZdAj_6e117MQHZAfxBFsg@mail.gmail.com>
1 parenta79a685 commitfa87870

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static intinitMasks(fd_set *rmask);
404404
staticvoidreport_fork_failure_to_client(Port*port,interrnum);
405405
staticCAC_statecanAcceptConnections(void);
406406
staticlongPostmasterRandom(void);
407-
staticvoidRandomSalt(char*md5Salt);
407+
staticvoidRandomSalt(char*salt,intlen);
408408
staticvoidsignal_child(pid_tpid,intsignal);
409409
staticboolSignalSomeChildren(intsignal,inttargets);
410410
staticvoidTerminateChildren(intsignal);
@@ -2342,7 +2342,7 @@ ConnCreate(int serverFd)
23422342
* after. Else the postmaster's random sequence won't get advanced, and
23432343
* all backends would end up using the same salt...
23442344
*/
2345-
RandomSalt(port->md5Salt);
2345+
RandomSalt(port->md5Salt,sizeof(port->md5Salt));
23462346

23472347
/*
23482348
* Allocate GSSAPI specific state struct
@@ -5083,23 +5083,21 @@ StartupPacketTimeoutHandler(void)
50835083
* RandomSalt
50845084
*/
50855085
staticvoid
5086-
RandomSalt(char*md5Salt)
5086+
RandomSalt(char*salt,intlen)
50875087
{
50885088
longrand;
5089+
inti;
50895090

50905091
/*
50915092
* We use % 255, sacrificing one possible byte value, so as to ensure that
50925093
* all bits of the random() value participate in the result. While at it,
50935094
* add one to avoid generating any null bytes.
50945095
*/
5095-
rand=PostmasterRandom();
5096-
md5Salt[0]= (rand %255)+1;
5097-
rand=PostmasterRandom();
5098-
md5Salt[1]= (rand %255)+1;
5099-
rand=PostmasterRandom();
5100-
md5Salt[2]= (rand %255)+1;
5101-
rand=PostmasterRandom();
5102-
md5Salt[3]= (rand %255)+1;
5096+
for (i=0;i<len;i++)
5097+
{
5098+
rand=PostmasterRandom();
5099+
salt[i]= (rand %255)+1;
5100+
}
51035101
}
51045102

51055103
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp