-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang-tidy] Move 'cert-msc51-cpp', 'cert-msc32-c' checks outside of 'cert' module and give a proper name #167143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luobochuanqi
wants to merge
9
commits into
llvm:main
Choose a base branch
from
luobochuanqi:cleanup-cert-module-random-seed-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−119
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fd994fd
[clang-tidy] Move 'cert-msc51-cpp', 'cert-msc32-c' checks outside of …
luobochuanqi ac312ee
Fix some grammar details and the documentation.
luobochuanqi aa56aae
Fix the documentation.
luobochuanqi 2841a2f
Fix the documentation.
luobochuanqi 47379b1
Format the file.
luobochuanqi 7feda4c
Update clang-tools-extra/docs/clang-tidy/checks/bugprone/random-gener…
luobochuanqi 3ce8e8e
Update clang-tools-extra/test/clang-tidy/checkers/bugprone/random-gen…
luobochuanqi b3462eb
Update clang-tools-extra/docs/clang-tidy/checks/list.rst
luobochuanqi 96384dc
Update random-generator-seed.c
luobochuanqi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
clang-tools-extra/docs/clang-tidy/checks/bugprone/random-generator-seed.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| .. title:: clang-tidy - bugprone-random-generator-seed | ||
|
|
||
| bugprone-random-generator-seed | ||
| ============================== | ||
|
|
||
| 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. | ||
|
|
||
| Examples: | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| void foo() { | ||
| std::mt19937 engine1; // Diagnose, always generate the same sequence | ||
| std::mt19937 engine2(1); // Diagnose | ||
| engine1.seed(); // Diagnose | ||
| engine2.seed(1); // Diagnose | ||
|
|
||
| std::time_t t; | ||
| engine1.seed(std::time(&t)); // Diagnose, system time might be controlled by user | ||
|
|
||
| int x = atoi(argv[1]); | ||
| std::mt19937 engine3(x); // Will not warn | ||
| } | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| .. option:: DisallowedSeedTypes | ||
|
|
||
| A comma-separated list of the type names which are disallowed. | ||
| Default value is `time_t,std::time_t`. | ||
|
|
||
| References | ||
| ---------- | ||
|
|
||
| This check corresponds to the CERT C++ Coding Standard rules | ||
| `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>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| .. title:: clang-tidy - cert-msc32-c | ||
| .. meta:: | ||
| :http-equiv=refresh: 5;URL=../cert/msc51-cpp.html | ||
| :http-equiv=refresh: 5;URL=../bugprone/random-generator-seed.html | ||
|
|
||
| cert-msc32-c | ||
| ============ | ||
|
|
||
| The `cert-msc32-c` check is an alias, please see | ||
| :doc:`cert-msc51-cpp <../cert/msc51-cpp>` for more information. | ||
| :doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed>` | ||
| for more information. | ||
|
|
||
| This check corresponds to the CERT C Coding Standard rule | ||
| `MSC32-C. Properly seed pseudorandom number generators | ||
| <https://wiki.sei.cmu.edu/confluence/display/c/MSC32-C.+Properly+seed+pseudorandom+number+generators>`_. |
42 changes: 8 additions & 34 deletions
42
clang-tools-extra/docs/clang-tidy/checks/cert/msc51-cpp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,14 @@ | ||
| .. title:: clang-tidy - cert-msc51-cpp | ||
| .. meta:: | ||
| :http-equiv=refresh: 5;URL=../bugprone/random-generator-seed.html | ||
|
|
||
| cert-msc51-cpp | ||
| ============== | ||
|
|
||
| This check 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: | ||
|
|
||
| .. code-block:: c++ | ||
|
|
||
| void foo() { | ||
| std::mt19937 engine1; // Diagnose, always generate the same sequence | ||
| std::mt19937 engine2(1); // Diagnose | ||
| engine1.seed(); // Diagnose | ||
| engine2.seed(1); // Diagnose | ||
|
|
||
| std::time_t t; | ||
| engine1.seed(std::time(&t)); // Diagnose, system time might be controlled by user | ||
| The `cert-msc51-cpp` check is an alias, please see | ||
| :doc:`bugprone-random-generator-seed <../bugprone/random-generator-seed>` | ||
| for more information. | ||
|
|
||
| int x = atoi(argv[1]); | ||
| std::mt19937 engine3(x); // Will not warn | ||
| } | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| .. option:: DisallowedSeedTypes | ||
|
|
||
| A comma-separated list of the type names which are disallowed. | ||
| Default value is `time_t,std::time_t`. | ||
| This check corresponds to the CERT C++ Coding Standard rule | ||
| `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>`_. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
...a/test/clang-tidy/checkers/cert/msc32-c.c → ...checkers/bugprone/random-generator-seed.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.