Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#include "ParentVirtualCallCheck.h"
#include "PointerArithmeticOnPolymorphicObjectCheck.h"
#include "PosixReturnCheck.h"
#include "ProperlySeededRandomGeneratorCheck.h"
#include "RandomGeneratorSeedCheck.h"
#include "RawMemoryCallOnNonTrivialTypeCheck.h"
#include "RedundantBranchConditionCheck.h"
#include "ReservedIdentifierCheck.h"
Expand Down Expand Up @@ -228,7 +228,7 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck<ParentVirtualCallCheck>(
"bugprone-parent-virtual-call");
CheckFactories.registerCheck<PosixReturnCheck>("bugprone-posix-return");
CheckFactories.registerCheck<ProperlySeededRandomGeneratorCheck>(
CheckFactories.registerCheck<RandomGeneratorSeedCheck>(
"bugprone-random-generator-seed");
CheckFactories.registerCheck<RawMemoryCallOnNonTrivialTypeCheck>(
"bugprone-raw-memory-call-on-non-trivial-type");
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ add_clang_library(clangTidyBugproneModule STATIC
ParentVirtualCallCheck.cpp
PointerArithmeticOnPolymorphicObjectCheck.cpp
PosixReturnCheck.cpp
ProperlySeededRandomGeneratorCheck.cpp
RandomGeneratorSeedCheck.cpp
RawMemoryCallOnNonTrivialTypeCheck.cpp
RedundantBranchConditionCheck.cpp
ReservedIdentifierCheck.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
//
//===----------------------------------------------------------------------===//

#include "ProperlySeededRandomGeneratorCheck.h"
#include "RandomGeneratorSeedCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/STLExtras.h"

using namespace clang::ast_matchers;

namespace clang::tidy::cert {
namespace clang::tidy::bugprone {

ProperlySeededRandomGeneratorCheck::ProperlySeededRandomGeneratorCheck(
RandomGeneratorSeedCheck::RandomGeneratorSeedCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
RawDisallowedSeedTypes(
Options.get("DisallowedSeedTypes", "time_t,std::time_t")) {
RawDisallowedSeedTypes.split(DisallowedSeedTypes, ',');
}

void ProperlySeededRandomGeneratorCheck::storeOptions(
void RandomGeneratorSeedCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "DisallowedSeedTypes", RawDisallowedSeedTypes);
}

void ProperlySeededRandomGeneratorCheck::registerMatchers(MatchFinder *Finder) {
void RandomGeneratorSeedCheck::registerMatchers(MatchFinder *Finder) {
auto RandomGeneratorEngineDecl = cxxRecordDecl(hasAnyName(
"::std::linear_congruential_engine", "::std::mersenne_twister_engine",
"::std::subtract_with_carry_engine", "::std::discard_block_engine",
Expand Down Expand Up @@ -75,7 +75,7 @@ void ProperlySeededRandomGeneratorCheck::registerMatchers(MatchFinder *Finder) {
this);
}

void ProperlySeededRandomGeneratorCheck::check(
void RandomGeneratorSeedCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructExpr>("ctor");
if (Ctor)
Expand All @@ -91,7 +91,7 @@ void ProperlySeededRandomGeneratorCheck::check(
}

template <class T>
void ProperlySeededRandomGeneratorCheck::checkSeed(
void RandomGeneratorSeedCheck::checkSeed(
const MatchFinder::MatchResult &Result, const T *Func) {
if (Func->getNumArgs() == 0 || Func->getArg(0)->isDefaultArgument()) {
diag(Func->getExprLoc(),
Expand All @@ -118,4 +118,4 @@ void ProperlySeededRandomGeneratorCheck::checkSeed(
}
}

} // namespace clang::tidy::cert
} // namespace clang::tidy::bugprone
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_PROPERLY_SEEDED_RANDOM_GENERATOR_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_PROPERLY_SEEDED_RANDOM_GENERATOR_H
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H

#include "../ClangTidyCheck.h"
#include <string>
Expand All @@ -21,9 +21,9 @@ namespace clang::tidy::bugprone {
///
/// For the user-facing documentation see:
/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/random-generator-seed.html
class ProperlySeededRandomGeneratorCheck : public ClangTidyCheck {
class RandomGeneratorSeedCheck : public ClangTidyCheck {
public:
ProperlySeededRandomGeneratorCheck(StringRef Name, ClangTidyContext *Context);
RandomGeneratorSeedCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Expand All @@ -39,4 +39,4 @@ class ProperlySeededRandomGeneratorCheck : public ClangTidyCheck {

} // namespace clang::tidy::bugprone

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_PROPERLY_SEEDED_RANDOM_GENERATOR_H
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_RANDOMGENERATORSEEDCHECK_H
8 changes: 3 additions & 5 deletions clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "../bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "../bugprone/FloatLoopCounterCheck.h"
#include "../bugprone/PointerArithmeticOnPolymorphicObjectCheck.h"
#include "../bugprone/ProperlySeededRandomGeneratorCheck.h"
#include "../bugprone/RandomGeneratorSeedCheck.h"
#include "../bugprone/RawMemoryCallOnNonTrivialTypeCheck.h"
#include "../bugprone/ReservedIdentifierCheck.h"
#include "../bugprone/SignalHandlerCheck.h"
Expand All @@ -41,8 +41,6 @@
#include "../readability/EnumInitialValueCheck.h"
#include "../readability/UppercaseLiteralSuffixCheck.h"
#include "LimitedRandomnessCheck.h"
#include "ProperlySeededRandomGeneratorCheck.h"
#include "MutatingCopyCheck.h"
#include "ThrownExceptionTypeCheck.h"

namespace {
Expand Down Expand Up @@ -273,7 +271,7 @@ class CERTModule : public ClangTidyModule {
"cert-mem57-cpp");
// MSC
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc50-cpp");
CheckFactories.registerCheck<bugprone::ProperlySeededRandomGeneratorCheck>(
CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
"cert-msc51-cpp");
CheckFactories.registerCheck<bugprone::SignalHandlerCheck>(
"cert-msc54-cpp");
Expand Down Expand Up @@ -326,7 +324,7 @@ class CERTModule : public ClangTidyModule {
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(
"cert-msc24-c");
CheckFactories.registerCheck<LimitedRandomnessCheck>("cert-msc30-c");
CheckFactories.registerCheck<bugprone::ProperlySeededRandomGeneratorCheck>(
CheckFactories.registerCheck<bugprone::RandomGeneratorSeedCheck>(
"cert-msc32-c");
CheckFactories.registerCheck<bugprone::UnsafeFunctionsCheck>(
"cert-msc33-c");
Expand Down
2 changes: 0 additions & 2 deletions clang-tools-extra/clang-tidy/cert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ set(LLVM_LINK_COMPONENTS
add_clang_library(clangTidyCERTModule STATIC
CERTTidyModule.cpp
LimitedRandomnessCheck.cpp
ProperlySeededRandomGeneratorCheck.cpp
MutatingCopyCheck.cpp
ThrownExceptionTypeCheck.cpp

LINK_LIBS
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ New check aliases
<clang-tidy/checks/bugprone/default-operator-new-on-overaligned-type>`
keeping initial check as an alias to the new one.

- Renamed :doc:`cert-msc32-c <clang-tidy/checks/cert/msc32-c>` to
:doc:`bugprone-random-generator-seed
<clang-tidy/checks/bugprone/random-generator-seed>`
keeping initial check as an alias to the new one.

- Renamed :doc:`cert-msc51-cpp <clang-tidy/checks/cert/msc51-cpp>` to
:doc:`bugprone-random-generator-seed
<clang-tidy/checks/bugprone/random-generator-seed>`
keeping initial check as an alias to the new one.

- Renamed :doc:`cert-oop57-cpp <clang-tidy/checks/cert/oop57-cpp>` to
:doc:`bugprone-raw-memory-call-on-non-trivial-type
<clang-tidy/checks/bugprone/raw-memory-call-on-non-trivial-type>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
bugprone-random-generator-seed
==============================

This check flags all pseudo-random number engines, engine adaptor
Flags all pseudo-random number engines, engine adaptor
instantiations and ``srand()`` when initialized or seeded with default argument,
constant expression or any user-configurable type. Pseudo-random number
engines seeded with a predictable value may cause vulnerabilities e.g. in
security protocols.
This is a CERT security rule, see
`MSC51-CPP. Ensure your random number generator is properly seeded
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_ and
`MSC32-C. Properly seed pseudorandom number generators
<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.

Examples:

Expand All @@ -38,3 +33,12 @@ Options

A comma-separated list of the type names which are disallowed.
Default value is `time_t,std::time_t`.

References
----------

This is a CERT security rule, see
`MSC51-CPP. Ensure your random number generator is properly seeded
<https://wiki.sei.cmu.edu/confluence/display/cplusplus/MSC51-CPP.+Ensure+your+random+number+generator+is+properly+seeded>`_ and
`MSC32-C. Properly seed pseudorandom number generators
<https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_.
2 changes: 1 addition & 1 deletion clang-tools-extra/docs/clang-tidy/checks/cert/msc32-c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ cert-msc32-c
============

The `cert-msc32-c` check is an alias, please see
:doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed>` for more information.
:doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed.html>` for more information.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ cert-msc51-cpp
==============

The `cert-msc51-cpp` check is an alias, please see
:doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed>` for more information.
:doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed.html>` for more information.
1 change: 1 addition & 0 deletions clang-tools-extra/docs/clang-tidy/checks/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ Check aliases
:doc:`cert-msc30-c <cert/msc30-c>`, :doc:`cert-msc50-cpp <cert/msc50-cpp>`,
:doc:`cert-msc32-c <cert/msc32-c>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
:doc:`cert-msc33-c <cert/msc33-c>`, :doc:`bugprone-unsafe-functions <bugprone/unsafe-functions>`,
:doc:`cert-msc51-cpp <cert/msc51-cpp>`, :doc:`bugprone-random-generator-seed <bugprone/random-generator-seed>`,
:doc:`cert-msc54-cpp <cert/msc54-cpp>`, :doc:`bugprone-signal-handler <bugprone/signal-handler>`,
:doc:`cert-oop11-cpp <cert/oop11-cpp>`, :doc:`performance-move-constructor-init <performance/move-constructor-init>`,
:doc:`cert-oop54-cpp <cert/oop54-cpp>`, :doc:`bugprone-unhandled-self-assignment <bugprone/unhandled-self-assignment>`,
Expand Down
Loading