Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fa87870

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

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/backend/postmaster/postmaster.c

+9-11
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int initMasks(fd_set *rmask);
404404
static void report_fork_failure_to_client(Port *port, int errnum);
405405
static CAC_state canAcceptConnections(void);
406406
static long PostmasterRandom(void);
407-
static void RandomSalt(char *md5Salt);
407+
static void RandomSalt(char *salt, int len);
408408
static void signal_child(pid_t pid, int signal);
409409
static bool SignalSomeChildren(int signal, int targets);
410410
static void TerminateChildren(int signal);
@@ -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
static void
5086-
RandomSalt(char *md5Salt)
5086+
RandomSalt(char *salt, int len)
50875087
{
50885088
long rand;
5089+
int i;
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)