[inventec] Replace os.system and remove subprocess with shell=True#12108
Merged
maipbui merged 2 commits intosonic-net:masterfrom Oct 14, 2022
Merged
[inventec] Replace os.system and remove subprocess with shell=True#12108maipbui merged 2 commits intosonic-net:masterfrom
maipbui merged 2 commits intosonic-net:masterfrom
Conversation
Signed-off-by: maipbui <[email protected]>
|
This pull request introduces 2 alerts and fixes 5 when merging 409c027 into 1effff9 - view on LGTM.com new alerts:
fixed alerts:
|
qiluo-msft
reviewed
Sep 19, 2022
|
|
||
| def get_platform(self): | ||
| if self.platform is None: | ||
| self.platform = os.popen("uname -n").read().strip() |
Collaborator
qiluo-msft
reviewed
Sep 19, 2022
| cmd = "i2cdetect -y "+str(FAN_VPD_CHANNEL)+" "+str(addr)+" "+str(addr)+" | grep "+str(hex(addr)).replace('0x','') | ||
| result=os.system(cmd) | ||
| cmd1 = ["i2cdetect", "-y", str(FAN_VPD_CHANNEL), str(addr), str(addr)] | ||
| cmd2 = ["grep", str(hex(addr)).replace('0x','')] |
Collaborator
There was a problem hiding this comment.
better way: https://stackoverflow.com/a/16414603/2514803 #Closed
Signed-off-by: maipbui <[email protected]>
|
This pull request introduces 2 alerts and fixes 5 when merging 799902a into 1f0699f - view on LGTM.com new alerts:
fixed alerts:
|
qiluo-msft
approved these changes
Oct 5, 2022
Contributor
Author
|
@klhaung @david-xk @CynthiaINV Could you help review and verify? |
linalvin
approved these changes
Oct 14, 2022
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Signed-off-by: maipbui [email protected]
Dependency: #12065
Why I did it
getstatusoutputis used without a static string and it usesshell=Truesubprocess()- when using withshell=Trueis dangerous. Using subprocess function without a static string can lead to command injection.os- not secure against maliciously constructed input and dangerous if used to evaluate dynamic content.How I did it
getstatusoutputwithout shell=Truesubprocess()- useshell=Falseinstead. use an array string. Ref: https://semgrep.dev/docs/cheat-sheets/python-command-injection/#mitigationos- use withsubprocessHow to verify it
Which release branch to backport (provide reason below if selected)
Description for the changelog
Ensure to add label/tag for the feature raised. example - PR#2174 where, Generic Config and Update feature has been labelled as GCU.
Link to config_db schema for YANG module changes
A picture of a cute animal (not mandatory but encouraged)