brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 2568099 Raw
45 lines · plain
1.. title:: clang-tidy - bugprone-random-generator-seed2 3bugprone-random-generator-seed4==============================5 6Flags all pseudo-random number engines, engine adaptor7instantiations and ``srand()`` when initialized or seeded with default8argument, constant expression or any user-configurable type. Pseudo-random9number engines seeded with a predictable value may cause vulnerabilities10e.g. in security protocols.11 12Examples:13 14.. code-block:: c++15 16  void foo() {17    std::mt19937 engine1; // Diagnose, always generate the same sequence18    std::mt19937 engine2(1); // Diagnose19    engine1.seed(); // Diagnose20    engine2.seed(1); // Diagnose21 22    std::time_t t;23    engine1.seed(std::time(&t)); // Diagnose, system time might be controlled by user24 25    int x = atoi(argv[1]);26    std::mt19937 engine3(x);  // Will not warn27  }28 29Options30-------31 32.. option:: DisallowedSeedTypes33 34   A comma-separated list of the type names which are disallowed.35   Default value is `time_t,std::time_t`.36 37References38----------39 40This check corresponds to the CERT C++ Coding Standard rules41`MSC51-CPP. Ensure your random number generator is properly seeded42<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_ and43`MSC32-C. Properly seed pseudorandom number generators44<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.45