From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 25 23:30:11 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5A13B37B401 for ; Fri, 25 Jul 2003 23:30:11 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7F95243F93 for ; Fri, 25 Jul 2003 23:30:09 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h6Q6U9Up072617 for ; Fri, 25 Jul 2003 23:30:09 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6Q6U97j072616; Fri, 25 Jul 2003 23:30:09 -0700 (PDT) Resent-Date: Fri, 25 Jul 2003 23:30:09 -0700 (PDT) Resent-Message-Id: <200307260630.h6Q6U97j072616@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "David Brinegar" Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3B31237B401 for ; Fri, 25 Jul 2003 23:28:33 -0700 (PDT) Received: from brinegar-computing.com (adsl-64-170-154-150.dsl.sntc01.pacbell.net [64.170.154.150]) by mx1.FreeBSD.org (Postfix) with SMTP id 9C63843F75 for ; Fri, 25 Jul 2003 23:28:32 -0700 (PDT) (envelope-from jot.3.brinegar@spamgourmet.com) Received: (qmail 5316 invoked by uid 1000); 26 Jul 2003 06:28:31 -0000 Message-Id: <20030726062831.5315.qmail@brinegar-computing.com> Date: 26 Jul 2003 06:28:31 -0000 From: "David Brinegar" To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/54878: incorrect divisor in /usr/bin/jot -r X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jul 2003 06:30:11 -0000 >Number: 54878 >Category: bin >Synopsis: incorrect divisor in /usr/bin/jot -r >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 25 23:30:09 PDT 2003 >Closed-Date: >Last-Modified: >Originator: David Brinegar >Release: FreeBSD 4.6-RELEASE i386 >Organization: >Environment: Any FreeBSD machine. >Description: src/usr.bin/jot/jot.c uses incorrect divisor. revision 1.24, line 278: *y = arc4random() / (double)UINT32_MAX; will 1 time in 2^32 assign 1.0 to *y, creating a distribution of [0,1] instead of the intended [0,1) spread. For example one would expect something like the following: > jot -w %d -r 1000 1 4 | sort -n | uniq -c 333 1 333 2 334 3 Internally, jot is assigning *y to 1,2,3, and very rarely 4: [1.0,2.0) => 1 [2.0,3.0) => 2 [3.0,4.0) => 3 4.0 => 4 So this bug creates the remote possiblity of something like: > jot -w %d -r 1000 1 4 | sort -n | uniq -c 333 1 333 2 333 3 1 4 >How-To-Repeat: jot -w $d -r 0 1 4 | grep 4 | head -1 and wait a potentially very long time. :-) >Fix: src/usr.bin/jot/jot.c revision 1.24, line 278: *y = arc4random() / (double)UINT32_MAX; should be: *y = arc4random() / (1.0 + (double)UINT32_MAX); and similar for other revisions, where the divisor should be one more than the maximum *random() function return value. >Release-Note: >Audit-Trail: >Unformatted: