Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Jan 2020 21:38:44 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356810 - head/usr.bin/random
Message-ID:  <202001162138.00GLciwT051082@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Thu Jan 16 21:38:44 2020
New Revision: 356810
URL: https://svnweb.freebsd.org/changeset/base/356810

Log:
  random(6): Fix off-by-one
  
  After r355693, random(6) -f sometimes fail to output all the lines of the
  input file.  This is because the range from which random indices are chosen
  is too big, so occasionally the random selection doesn't correspond to any
  line and nothing gets printed.
  
  (Ed. note: Mea culpa.  Working on r355693, I was confused by the sometime
  use of 1-indexing, sometimes 0-indexing in randomize_fd().)
  
  Submitted by:	Ryan Moeller <ryan AT freqlabs.com>
  X-MFC-With:	r355693
  Sponsored by:	iXsystems, Inc.
  Differential Revision:	https://reviews.freebsd.org/D23199

Modified:
  head/usr.bin/random/randomize_fd.c

Modified: head/usr.bin/random/randomize_fd.c
==============================================================================
--- head/usr.bin/random/randomize_fd.c	Thu Jan 16 21:31:56 2020	(r356809)
+++ head/usr.bin/random/randomize_fd.c	Thu Jan 16 21:38:44 2020	(r356810)
@@ -211,7 +211,7 @@ make_token:
 	free(buf);
 
 	for (i = numnode; i > 0; i--) {
-		selected = arc4random_uniform(numnode + 1);
+		selected = arc4random_uniform(numnode);
 
 		for (j = 0, prev = n = rand_root; n != NULL; j++, prev = n, n = n->next) {
 			if (j == selected) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202001162138.00GLciwT051082>