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

Commit755c00a

Browse files
committed
Auto-seed random so user's can't request random values based on
our postmaster random seed used from cancel.
1 parent19a95d9 commit755c00a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎src/backend/utils/adt/misc.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.12 1998/02/24 03:47:26 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.13 1998/06/09 19:20:59 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
1414
#include<sys/types.h>
1515
#include<sys/file.h>
16+
#include<time.h>
1617
#include"postgres.h"
1718
#include"utils/datum.h"
1819
#include"catalog/pg_type.h"
@@ -60,6 +61,9 @@ nonnullvalue(Datum value, bool *isNull)
6061
* will return about 1/10 of the tuples in TEMP
6162
*
6263
*/
64+
65+
staticboolrandom_initialized= false;
66+
6367
bool
6468
oidrand(Oido,int32X)
6569
{
@@ -68,6 +72,17 @@ oidrand(Oid o, int32 X)
6872
if (X==0)
6973
return true;
7074

75+
/*
76+
*We do this because the cancel key is actually a random, so we don't
77+
*want them to be able to request random numbers using our postmaster
78+
*seeded value.
79+
*/
80+
if (!random_initialized)
81+
{
82+
srandom((unsignedint)time(NULL));
83+
random_initialized= true;
84+
}
85+
7186
result= (random() %X==0);
7287
returnresult;
7388
}
@@ -81,6 +96,7 @@ bool
8196
oidsrand(int32X)
8297
{
8398
srand(X);
99+
random_initialized= true;
84100
return true;
85101
}
86102

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp