Browse Source

Add linker warnings for rand() and random() and various related functions.

ok deraadt@
OPENBSD_5_5
kettenis 11 years ago
parent
commit
9a1134ebb6
2 changed files with 31 additions and 1 deletions
  1. +15
    -0
      src/lib/libc/stdlib/rand.c
  2. +16
    -1
      src/lib/libc/stdlib/random.c

+ 15
- 0
src/lib/libc/stdlib/rand.c View File

@ -39,14 +39,29 @@ rand_r(u_int *seed)
return (*seed % ((u_int)RAND_MAX + 1)); return (*seed % ((u_int)RAND_MAX + 1));
} }
#if defined(APIWARN)
__warn_references(rand_r,
"warning: rand_r() isn't random; consider using arc4random()");
#endif
int int
rand(void) rand(void)
{ {
return (rand_r(&next)); return (rand_r(&next));
} }
#if defined(APIWARN)
__warn_references(rand,
"warning: rand() isn't random; consider using arc4random()");
#endif
void void
srand(u_int seed) srand(u_int seed)
{ {
next = seed; next = seed;
} }
#if defined(APIWARN)
__warn_references(srand,
"warning: srand() seed choices are invariably poor");
#endif

+ 16
- 1
src/lib/libc/stdlib/random.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: random.c,v 1.18 2013/03/15 19:07:53 tedu Exp $ */
/* $OpenBSD: random.c,v 1.19 2013/08/01 19:42:08 kettenis Exp $ */
/* /*
* Copyright (c) 1983 Regents of the University of California. * Copyright (c) 1983 Regents of the University of California.
* All rights reserved. * All rights reserved.
@ -233,6 +233,11 @@ srandom(unsigned int x)
UNLOCK(); UNLOCK();
} }
#if defined(APIWARN)
__warn_references(srandom,
"warning: srandom() seed choices are invariably poor");
#endif
/* /*
* srandomdev: * srandomdev:
* *
@ -267,6 +272,11 @@ srandomdev(void)
UNLOCK(); UNLOCK();
} }
#if defined(APIWARN)
__warn_references(srandomdev,
"warning: srandomdev() usage; consider switching to arc4random()");
#endif
/* /*
* initstate: * initstate:
* *
@ -429,3 +439,8 @@ random(void)
UNLOCK(); UNLOCK();
return r; return r;
} }
#if defined(APIWARN)
__warn_references(random,
"warning: random() isn't random; consider using arc4random()");
#endif

Loading…
Cancel
Save