Re: [HACKERS] Re: Cancel key now ready
От | Bruce Momjian |
---|---|
Тема | Re: [HACKERS] Re: Cancel key now ready |
Дата | |
Msg-id | 199806091920.PAA03144@candle.pha.pa.us обсуждение исходный текст |
Ответ на | Re: [HACKERS] Re: Cancel key now ready (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
Here is a patch that will auto-seed any request for random from the user. This will prevent users from seeing random values that use our postmaster cancel seed. --------------------------------------------------------------------------- Index: src/backend/utils/adt/misc.c =================================================================== RCS file: /usr/local/cvsroot/pgsql/src/backend/utils/adt/misc.c,v retrieving revision 1.12 diff -c -r1.12 misc.c *** misc.c 1998/02/24 03:47:26 1.12 --- misc.c 1998/06/09 19:16:16 *************** *** 13,18 **** --- 13,19 ---- */ #include <sys/types.h> #include <sys/file.h> + #include <time.h> #include "postgres.h" #include "utils/datum.h" #include "catalog/pg_type.h" *************** *** 60,65 **** --- 61,69 ---- * will return about 1/10 of the tuples in TEMP * */ + + static bool random_initialized = false; + bool oidrand(Oid o, int32 X) { *************** *** 68,73 **** --- 72,88 ---- if (X == 0) return true; + /* + * We do this because the cancel key is actually a random, so we don't + * want them to be able to request random numbers using our postmaster + * seeded value. + */ + if (!random_initialized) + { + srandom((unsigned int)time(NULL)); + random_initialized = true; + } + result = (random() % X == 0); return result; } *************** *** 81,86 **** --- 96,102 ---- oidsrand(int32 X) { srand(X); + random_initialized = true; return true; } -- Bruce Momjian | 830 Blythe Avenue maillist@candle.pha.pa.us | Drexel Hill, Pennsylvania 19026 + If your life is a hard drive, | (610) 353-9879(w) + Christ can be your backup. | (610) 853-3000(h)
В списке pgsql-hackers по дате отправления: