Closed
Bug 867769
Opened 12 years ago
Closed 12 years ago
NS_MakeRandomString generates the same string when called twice within the same second
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
FIXED
mozilla23
People
(Reporter: dhylands, Assigned: dhylands)
Details
Attachments
(1 file)
|
1.07 KB,
patch
|
benjamin
:
review+
|
Details | Diff | Splinter Review |
NS_MakeRandomString reseeds the random generator each time its called.
It essentially uses the current time measured in seconds as the seed, so if you call it twice within the same second, you'll get the same random string back.
I think it should only set the seed once.
DeviceStorage's Add function currently uses this, and it seems quite plausible that Add could be called more that once in the same second.
| Assignee | ||
Updated•12 years ago
|
Assignee: nobody → dhylands
| Assignee | ||
Comment 1•12 years ago
|
||
| Assignee | ||
Updated•12 years ago
|
Attachment #744291 -
Flags: review?(benjamin)
| Assignee | ||
Comment 2•12 years ago
|
||
Comment on attachment 744291 [details] [diff] [review]
Make it so we only set the seed the first time that NS_MakeRandomString is called.
Review of attachment 744291 [details] [diff] [review]:
-----------------------------------------------------------------
::: xpcom/glue/nsCRTGlue.cpp
@@ +253,5 @@
> // and salt rand with that.
> + static unsigned int seed = 0;
> + if (seed == 0) {
> + double fpTime = double(PR_Now());
> + seed = (unsigned int)(fpTime * 1e-6 + 0.5) // use 1e-6, granularity of PR_Now() on the mac is seconds
nit: Forgot to refresh before attaching the patch, and this line is missing a semi-colon.
Updated•12 years ago
|
Attachment #744291 -
Flags: review?(benjamin) → review+
| Assignee | ||
Comment 3•12 years ago
|
||
Comment 4•12 years ago
|
||
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in
before you can comment on or make changes to this bug.
Description
•