Fix typo in pg_srand48 (srand48 in older branches).
authorTom Lane <[email protected]>
Sat, 3 Sep 2011 20:17:52 +0000 (16:17 -0400)
committerTom Lane <[email protected]>
Sat, 3 Sep 2011 20:17:52 +0000 (16:17 -0400)
">" should be ">>".  This typo results in failure to use all of the bits
of the provided seed.

This might rise to the level of a security bug if we were relying on
srand48 for any security-critical purposes, but we are not --- in fact,
it's not used at all unless the platform lacks srandom(), which is
improbable.  Even on such a platform the exposure seems minimal.

Reported privately by Andres Freund.

src/port/rand.c

index 8559ef8c175fa37dcd5b8680a3318c3be81e6ec8..5982ef9cb72e329904b0d1d3b0ab87cbdd1d73ed 100644 (file)
@@ -74,7 +74,7 @@ srand48(long seed)
 {
        _rand48_seed[0] = RAND48_SEED_0;
        _rand48_seed[1] = (unsigned short) seed;
-       _rand48_seed[2] = (unsigned short) (seed > 16);
+       _rand48_seed[2] = (unsigned short) (seed >> 16);
        _rand48_mult[0] = RAND48_MULT_0;
        _rand48_mult[1] = RAND48_MULT_1;
        _rand48_mult[2] = RAND48_MULT_2;