patch-kuser_generate-requests_c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. $OpenBSD: patch-kuser_generate-requests_c,v 1.2 2016/12/17 14:58:31 ajacoutot Exp $
  2. Use HAVE_ARC4RANDOM and choose to call arc4random() instead of srand()
  3. and rand() and friends.
  4. --- kuser/generate-requests.c.orig Tue Nov 29 02:35:27 2016
  5. +++ kuser/generate-requests.c Thu Dec 15 11:29:38 2016
  6. @@ -67,7 +67,7 @@ generate_requests (const char *filename, unsigned nreq
  7. krb5_context context;
  8. krb5_error_code ret;
  9. krb5_creds cred;
  10. - int i;
  11. + int i, rnd;
  12. char **words;
  13. unsigned nwords;
  14. @@ -78,7 +78,12 @@ generate_requests (const char *filename, unsigned nreq
  15. nwords = read_words (filename, &words);
  16. for (i = 0; i < nreq; ++i) {
  17. - char *name = words[rand() % nwords];
  18. +#ifdef HAVE_ARC4RANDOM
  19. + rnd = arc4random();
  20. +#else
  21. + rnd = rand();
  22. +#endif
  23. + char *name = words[rnd % nwords];
  24. memset(&cred, 0, sizeof(cred));
  25. @@ -137,7 +142,9 @@ main(int argc, char **argv)
  26. if (argc != 2)
  27. usage (1);
  28. +#ifndef HAVE_ARC4RANDOM
  29. srand (0);
  30. +#endif
  31. nreq = strtol (argv[1], &end, 0);
  32. if (argv[1] == end || *end != '\0')
  33. usage (1);