summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2013-08-01 19:42:09 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2013-08-01 19:42:09 +0000
commit773a69f55748d3ee34cc366470a8aa89271f5382 (patch)
tree3c80d1cbbbf1d95d032f39c0ebc03e41bf1e1586 /lib/libc/stdlib
parent99e4bd039f12d6ae201fafcb4e6d632519ce2027 (diff)
Add linker warnings for rand() and random() and various related functions.
ok deraadt@
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/rand.c15
-rw-r--r--lib/libc/stdlib/random.c17
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c
index 0f9c100807f..6860dd4f712 100644
--- a/lib/libc/stdlib/rand.c
+++ b/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/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c
index f299d8e2f65..00edf2dca1c 100644
--- a/lib/libc/stdlib/random.c
+++ b/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