diff options
Diffstat (limited to 'src/lib/libc/stdlib')
| -rw-r--r-- | src/lib/libc/stdlib/rand.c | 15 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/random.c | 17 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/lib/libc/stdlib/rand.c b/src/lib/libc/stdlib/rand.c index 0f9c100807..6860dd4f71 100644 --- a/src/lib/libc/stdlib/rand.c +++ b/src/lib/libc/stdlib/rand.c | |||
| @@ -39,14 +39,29 @@ rand_r(u_int *seed) | |||
| 39 | return (*seed % ((u_int)RAND_MAX + 1)); | 39 | return (*seed % ((u_int)RAND_MAX + 1)); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | #if defined(APIWARN) | ||
| 43 | __warn_references(rand_r, | ||
| 44 | "warning: rand_r() isn't random; consider using arc4random()"); | ||
| 45 | #endif | ||
| 46 | |||
| 42 | int | 47 | int |
| 43 | rand(void) | 48 | rand(void) |
| 44 | { | 49 | { |
| 45 | return (rand_r(&next)); | 50 | return (rand_r(&next)); |
| 46 | } | 51 | } |
| 47 | 52 | ||
| 53 | #if defined(APIWARN) | ||
| 54 | __warn_references(rand, | ||
| 55 | "warning: rand() isn't random; consider using arc4random()"); | ||
| 56 | #endif | ||
| 57 | |||
| 48 | void | 58 | void |
| 49 | srand(u_int seed) | 59 | srand(u_int seed) |
| 50 | { | 60 | { |
| 51 | next = seed; | 61 | next = seed; |
| 52 | } | 62 | } |
| 63 | |||
| 64 | #if defined(APIWARN) | ||
| 65 | __warn_references(srand, | ||
| 66 | "warning: srand() seed choices are invariably poor"); | ||
| 67 | #endif | ||
diff --git a/src/lib/libc/stdlib/random.c b/src/lib/libc/stdlib/random.c index f299d8e2f6..00edf2dca1 100644 --- a/src/lib/libc/stdlib/random.c +++ b/src/lib/libc/stdlib/random.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: random.c,v 1.18 2013/03/15 19:07:53 tedu Exp $ */ | 1 | /* $OpenBSD: random.c,v 1.19 2013/08/01 19:42:08 kettenis Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 1983 Regents of the University of California. | 3 | * Copyright (c) 1983 Regents of the University of California. |
| 4 | * All rights reserved. | 4 | * All rights reserved. |
| @@ -233,6 +233,11 @@ srandom(unsigned int x) | |||
| 233 | UNLOCK(); | 233 | UNLOCK(); |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | #if defined(APIWARN) | ||
| 237 | __warn_references(srandom, | ||
| 238 | "warning: srandom() seed choices are invariably poor"); | ||
| 239 | #endif | ||
| 240 | |||
| 236 | /* | 241 | /* |
| 237 | * srandomdev: | 242 | * srandomdev: |
| 238 | * | 243 | * |
| @@ -267,6 +272,11 @@ srandomdev(void) | |||
| 267 | UNLOCK(); | 272 | UNLOCK(); |
| 268 | } | 273 | } |
| 269 | 274 | ||
| 275 | #if defined(APIWARN) | ||
| 276 | __warn_references(srandomdev, | ||
| 277 | "warning: srandomdev() usage; consider switching to arc4random()"); | ||
| 278 | #endif | ||
| 279 | |||
| 270 | /* | 280 | /* |
| 271 | * initstate: | 281 | * initstate: |
| 272 | * | 282 | * |
| @@ -429,3 +439,8 @@ random(void) | |||
| 429 | UNLOCK(); | 439 | UNLOCK(); |
| 430 | return r; | 440 | return r; |
| 431 | } | 441 | } |
| 442 | |||
| 443 | #if defined(APIWARN) | ||
| 444 | __warn_references(random, | ||
| 445 | "warning: random() isn't random; consider using arc4random()"); | ||
| 446 | #endif | ||
