jcoglan/faye-websocket-node — Issue #7: Buggy use of math.random
Author: majek
Created: 2011-12-16 14:43:12+00:00
State: open

Line https://github.com/jcoglan/faye-websocket-node/blob/master/lib/faye/websocket/protocol8_parser.js#L201 is buggy.

function() { return Math.floor(Math.random() * 255) })

By definition returns value from 0...254 inclusive. Not 255.

It's very easy to verify:

a = function() { return Math.floor(Math.random() * 255) }
g = {}
for (var i=0; i<1000000; i++) {x = a(); if( !(x in g)) g[x]=0; g[x] += 1;}

there won't be anything set for g[255]. I don't think that was intended.

This one is even worse: https://github.com/jcoglan/faye-websocket-node/blob/master/lib/faye/websocket/protocol8_parser.js#L8