Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] Re: Cancel key now ready

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us (Tom Lane)
Cc: hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: Cancel key now ready
Date: 1998-06-09 19:20:02
Message-ID: 199806091920.PAA03144@candle.pha.pa.us (view raw or flat)
Thread:
Lists: 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(at)candle(dot)pha(dot)pa(dot)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)

In response to

pgsql-hackers by date

Next:From: Brandon IbachDate: 1998-06-09 20:21:12
Subject: Table corrupt?
Previous:From: Bruce MomjianDate: 1998-06-09 17:30:17
Subject: Re: [HACKERS] Postmaster not starting

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group