File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 8
8
#include < wincrypt.h>
9
9
#else
10
10
#include < random>
11
+ #include < thread>
12
+ #include < ctime>
11
13
#endif
12
14
13
15
namespace Sass {
@@ -36,9 +38,23 @@ namespace Sass {
36
38
CryptGenRandom (hp, sizeof (seed), (BYTE*)&seed);
37
39
CryptReleaseContext (hp, 0 );
38
40
#else
39
- // Get seed via C++11 API
40
- std::random_device rd;
41
- seed = rd ();
41
+ // Try to get random number from system
42
+ try {
43
+ // Get seed via C++11 API
44
+ std::random_device rd;
45
+ seed = rd ();
46
+ }
47
+ // On certain system this can throw since either
48
+ // underlying hardware or software can be buggy.
49
+ // https://github.com/sass/libsass/issues/3151
50
+ catch (std::exception&) {
51
+ }
52
+ // Don't trust anyone to be random, so we
53
+ // add a little entropy of our own.
54
+ seed ^= std::time (NULL ) ^ std::clock () ^
55
+ std::hash<std::thread::id>()
56
+ (std::this_thread::get_id ());
57
+ // Return entropy
42
58
#endif
43
59
}
44
60
// Use some sensible default
You can’t perform that action at this time.
0 commit comments