diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 0f9c1008..6860dd4f 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c @@ -39,14 +39,29 @@ rand_r(u_int *seed) 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 rand(void) { return (rand_r(&next)); } +#if defined(APIWARN) +__warn_references(rand, + "warning: rand() isn't random; consider using arc4random()"); +#endif + void srand(u_int seed) { next = seed; } + +#if defined(APIWARN) +__warn_references(srand, + "warning: srand() seed choices are invariably poor"); +#endif diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c index f299d8e2..00edf2dc 100644 --- a/src/lib/libc/stdlib/random.c +++ b/src/lib/libc/stdlib/random.c @@ -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. * All rights reserved. @@ -233,6 +233,11 @@ srandom(unsigned int x) UNLOCK(); } +#if defined(APIWARN) +__warn_references(srandom, + "warning: srandom() seed choices are invariably poor"); +#endif + /* * srandomdev: * @@ -267,6 +272,11 @@ srandomdev(void) UNLOCK(); } +#if defined(APIWARN) +__warn_references(srandomdev, + "warning: srandomdev() usage; consider switching to arc4random()"); +#endif + /* * initstate: * @@ -429,3 +439,8 @@ random(void) UNLOCK(); return r; } + +#if defined(APIWARN) +__warn_references(random, + "warning: random() isn't random; consider using arc4random()"); +#endif