jot random number generator broken in batch jobs

Bug #804355 reported by SaveTheRbtz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
athena-jot (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

jot -r generates same random numbers within one second time so it's unusable in batch jobs like shell scripts.

There is code for initializing "random" seed:
    s = (randomize ? time(0) : STEP_DEF);
    /*... snip ....*/
    srand((int) s);

Here is an example of this behavior:
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455778
9981995
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455779
2355993
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455780
3745306
rbtz@rbtz-desktop:~$ date +%s; jot -r 1 0 10000000
1309455780
3745306

As fast fix pid can be added to seed
srandom((int) s ^ (getpid()<<4));

As good fix arc4random or similar mechanism can be used.

Tags: patch

Related branches

Revision history for this message
SaveTheRbtz (savetherbtz) wrote :

Provided patch solving this issue.

Revision history for this message
Ubuntu Foundations Team Bug Bot (crichton) wrote :

The attachment "jot-9.0-random-number-geterator.patch" of this bug report has been identified as being a patch in the form of a debdiff. The ubuntu-sponsors team has been subscribed to the bug report so that they can review and hopefully sponsor the debdiff. In the event that this is in fact not a patch you can resolve this situation by removing the tag 'patch' from the bug report and editing the attachment so that it is not flagged as a patch. Additionally, if you are member of the ubuntu-sponsors team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by Brian Murray. Please contact him regarding any issues with the action taken in this bug report.]

tags: added: patch
Revision history for this message
James Page (james-page) wrote :

Thanks for taking the time to prepare this patch.

Some feedback on the update:

1) debian/changelog

athena-jot (9.0-5yandex0) oneiric; urgency=low

a) oneiric development has close since its now been released - your fix needs to target precise.

b) 9.0-5yandex0 works but is not inline with the way the version should be incremented - 9.0-5ubuntu1 would be appropriate.

* Use arc4random number generation instead of time based

You should add (LP: #804355) to the changelog entry - that way this bug would be closed when the package is accepted into the archive.

2) patching

This is quite an older package and pre-dates some of the newer package format options; it would be nice to switch this package over to source/format 3.0 and provide the fixes as a patch rather than changing the upstream source code directly.

See http://wiki.debian.org/Projects/DebSrc3.0

Thanks for you work so far!

Cheers

James

Revision history for this message
SaveTheRbtz (savetherbtz) wrote :

Oh... Previous patch by any means was not supposed to go to mainline. It was just dirty-hacky-PoC.

Here is our QA version. Changes:
* Switched to dpkg-source 3.0 (quilt) format
* Added dbg package
* Removed auto-generated files
* Applied arc4random patch

PS. I'm .rpm guy so I could messed up something there.
PPS. Could it be also backported to Lucid?

Revision history for this message
James Page (james-page) wrote :

@SaveTheRbtz

Thanks for the updated patch - that sure is alot of changes!

One of my fellow core-dev's pointed out to me that changing the structure of the source package is not recommended in Ubuntu as it makes merging from Debian if/when they change much more difficult - apologies for the bad advice.

It would make sense to submit these wider impacting changes back to Debian - please see https://wiki.ubuntu.com/Debian/Bugs for more information on how todo this.

I've rationalized your revised patch into the original packaging for upload to Ubuntu.

Please feel free to request that this is backported to Lucid - https://wiki.ubuntu.com/UbuntuBackports has more details on how todo this.

Thanks for your contribution to Ubuntu!

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package athena-jot - 9.0-5ubuntu1

---------------
athena-jot (9.0-5ubuntu1) precise; urgency=low

  * Use arc4random number generation instead of time based (LP: #804355).
    - d/control: Add Build-Depends - libbsd-dev, dh-autoreconf.
    - d/rules: Updated to call dh_autoreconf.
 -- Alexey Ivanov <email address hidden> Mon, 26 Mar 2012 15:10:40 +0100

Changed in athena-jot (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.