Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===--- ProperlySeededRandomGeneratorCheck.h - clang-tidy-------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H |
| 10 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H |
| 11 | |
| 12 | #include "../ClangTidyCheck.h" |
| 13 | #include <string> |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace cert { |
| 18 | |
| 19 | /// Random number generator must be seeded properly. |
| 20 | /// |
| 21 | /// A random number generator initialized with default value or a |
| 22 | /// constant expression is a security vulnerability. |
| 23 | /// |
| 24 | /// For the user-facing documentation see: |
| 25 | /// http://clang.llvm.org/extra/clang-tidy/checks/cert-properly-seeded-random-generator.html |
| 26 | class ProperlySeededRandomGeneratorCheck : public ClangTidyCheck { |
| 27 | public: |
| 28 | ProperlySeededRandomGeneratorCheck(StringRef Name, ClangTidyContext *Context); |
| 29 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
| 30 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 31 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 32 | |
| 33 | private: |
| 34 | template <class T> |
| 35 | void checkSeed(const ast_matchers::MatchFinder::MatchResult &Result, |
| 36 | const T *Func); |
| 37 | |
| 38 | std::string RawDisallowedSeedTypes; |
| 39 | SmallVector<StringRef, 5> DisallowedSeedTypes; |
| 40 | }; |
| 41 | |
| 42 | } // namespace cert |
| 43 | } // namespace tidy |
| 44 | } // namespace clang |
| 45 | |
| 46 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H |