clang-tools 10.0.0

ProperlySeededRandomGeneratorCheck.h
Go to the documentation of this file.
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
clang::tidy::cert::ProperlySeededRandomGeneratorCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: ProperlySeededRandomGeneratorCheck.cpp:33
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::cert::ProperlySeededRandomGeneratorCheck::ProperlySeededRandomGeneratorCheck
ProperlySeededRandomGeneratorCheck(StringRef Name, ClangTidyContext *Context)
Definition: ProperlySeededRandomGeneratorCheck.cpp:20
clang::tidy::cert::ProperlySeededRandomGeneratorCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: ProperlySeededRandomGeneratorCheck.cpp:28
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
clang::tidy::cert::ProperlySeededRandomGeneratorCheck
Random number generator must be seeded properly.
Definition: ProperlySeededRandomGeneratorCheck.h:26
clang::tidy::cert::ProperlySeededRandomGeneratorCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: ProperlySeededRandomGeneratorCheck.cpp:78