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::tidy::cert { |
16 | |
17 | /// Random number generator must be seeded properly. |
18 | /// |
19 | /// A random number generator initialized with default value or a |
20 | /// constant expression is a security vulnerability. |
21 | /// |
22 | /// For the user-facing documentation see: |
23 | /// http://clang.llvm.org/extra/clang-tidy/checks/cert/msc51-cpp.html |
24 | class ProperlySeededRandomGeneratorCheck : public ClangTidyCheck { |
25 | public: |
26 | ProperlySeededRandomGeneratorCheck(StringRef Name, ClangTidyContext *Context); |
27 | void storeOptions(ClangTidyOptions::OptionMap &Opts) override; |
28 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
29 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
30 | |
31 | private: |
32 | template <class T> |
33 | void checkSeed(const ast_matchers::MatchFinder::MatchResult &Result, |
34 | const T *Func); |
35 | |
36 | std::string RawDisallowedSeedTypes; |
37 | SmallVector<StringRef, 5> DisallowedSeedTypes; |
38 | }; |
39 | |
40 | } // namespace clang::tidy::cert |
41 | |
42 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_PROPERLY_SEEDED_RANDOM_GENERATOR_H |
43 | |