Bug 81279

Summary: /usr/games/random returns every line
Product: Base System Reporter: Vick Khera <vivek>
Component: amd64Assignee: freebsd-amd64 (Nobody) <amd64>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 5.3-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
random.c.patch none

Description Vick Khera 2005-05-19 19:50:01 UTC
	

Running /usr/games/random to select lines from a file fails to eliminate any
lines -- ie, it functions just like "cat".

Fix: 

no idea.  must be some 64-bit over/under flow issue...
How-To-Repeat: 	

make a file with 10000 lines for easy viewing:

perl -e 'print "$_\n" for (1..10000)' > list

now run

/usr/games/random 6 < list > out

On an amd64 system, list == out.  On an i386 system the file out has
approximately 1600 lines.
Comment 1 groot 2005-05-19 22:26:08 UTC
Problem is lines like

        selected = (int)(denom * random() / LONG_MAX) == 0;

which cause the overflow. Replacing LONG_MAX with INT_MAX here fixes the bug. 
(The same replacement should probably be done in the other two places that 
LONG_MAX occurs, since the -e flag is similarly broken.)

-- 
These are your friends - Adem
    GPG: FEA2 A3FE Adriaan de Groot
Comment 2 Vick Khera 2005-05-20 20:36:55 UTC
Here's a patch for /usr/src/games/random/random.c which seems to  
solve the problem, based on Adriaan's message.

Comment 3 John Baldwin freebsd_committer freebsd_triage 2005-05-27 16:29:13 UTC
State Changed
From-To: open->patched

Fix committed to HEAD.  Will MFC after a week.
Comment 4 John Baldwin freebsd_committer freebsd_triage 2005-06-29 16:20:28 UTC
State Changed
From-To: patched->closed

Fix committed to RELENG_5.