Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure chttpd pids have a proper random seed #841

Closed
wants to merge 1 commit into from

Conversation

chewbranca
Copy link
Contributor

Overview

Currently chttpd pids are not properly seeded for random number generation. This ensures that they are.

Testing recommendations

GitHub issue number

Related Pull Requests

Checklist

  • Code is written and works correctly;
  • Changes are covered by tests;
  • Documentation reflects the changes;

@nickva
Copy link
Contributor

nickva commented Sep 26, 2017

+1

@davisp
Copy link
Member

davisp commented Sep 26, 2017

Don't you need an /integer specification on those?

@davisp
Copy link
Member

davisp commented Sep 26, 2017

Also might make sense to pull it out into a function.

@nickva
Copy link
Contributor

nickva commented Sep 26, 2017

Integer is the default, I think

@davisp
Copy link
Member

davisp commented Sep 26, 2017

Huh. I would've expected binary as the default but I guess I just add specifiers out of habit.

@chewbranca
Copy link
Contributor Author

Yeah I'm thinking we would be better served by a function like:

maybe_seed() ->
    case get(random_seed) of
        undefined ->
            <<A:32, B:32, C:32>> = crypto:rand_bytes(12),
            Seed = {A, B, C},
            random:seed(Seed),
            Seed;
        Seed ->
            Seed
end.

@chewbranca
Copy link
Contributor Author

It's a shame we can't use the rand module, as rand takes care of this automatically, but it's not in all the versions of Erlang we support. The random module has a terrible default seed: https://github.com/erlang/otp/blob/master/lib/stdlib/src/random.erl#L44-L45

@nickva
Copy link
Contributor

nickva commented Sep 26, 2017

@chewbranca why terrible? It's a perfectly fine randomly chosen number :P

https://www.xkcd.com/221/

@nickva
Copy link
Contributor

nickva commented Sep 26, 2017

@davisp agree. Binary would seem to be a default type for a ... binary. Not sure why integers were picked.

@chewbranca
Copy link
Contributor Author

@nickva well if {3172, 9814, 20125}. was chosen by way of random dice roll then we should be good. I feel bad for whoever had to roll dice that many times, although perhaps they had help from Emanuel Czuber.

@chewbranca
Copy link
Contributor Author

Closing this out.

@chewbranca chewbranca closed this Sep 26, 2017
@wohali wohali deleted the random-seed-chttpd-pids branch October 21, 2020 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants