-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[nokia] Replace os.system and remove subprocess with shell=True #12100
Conversation
Signed-off-by: maipbui <maibui@microsoft.com>
Signed-off-by: maipbui <maibui@microsoft.com>
Signed-off-by: maipbui <maibui@microsoft.com>
Signed-off-by: maipbui <maibui@microsoft.com>
os.system("echo 24c02 0x53 > /sys/class/i2c-adapter/i2c-0/new_device") | ||
file = "/sys/class/i2c-adapter/i2c-0/new_device" | ||
with open(file, 'w') as f: | ||
f.write('24c02 0x53') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -331,7 +327,7 @@ def set_status_led(self, color): | |||
|
|||
# Write sys led | |||
if smbus_present == 0: # called from host (e.g. 'show system-health') | |||
cmdstatus, value = cmd.getstatusoutput('sudo i2cset -y 0 0x41 0x7 %d' % value) | |||
cmdstatus, value = getstatusoutput_noshell(['sudo', 'i2cset', '-y', '0', '0x41', '0x7', value]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: maipbui <maibui@microsoft.com>
Signed-off-by: maipbui <maibui@microsoft.com>
@carl-nokia @dflynn-Nokia Could you help review and verify? |
@mlok-nokia Could you help review and verify? |
/azp run Azure.sonic-buildimage |
Azure Pipelines successfully started running 1 pipeline(s). |
@Blueve is connecting Nokia reviewers. |
I am ok with the change. Thanks |
Signed-off-by: maipbui maibui@microsoft.com
Dependency: #12065
Why I did it
subprocess.Popen()
andsubprocess.run()
is used withshell=True
, which is very dangerous for shell injection.os
- not secure against maliciously constructed input and dangerous if used to evaluate dynamic contentgetstatusoutput
is dangerous because it containsshell=True
in the implementationHow I did it
Replace
os
bysubprocess
, use withshell=False
Remove unused functions
How 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)