Skip to content
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

[device/centec] Replace os.system and remove subprocess with shell=True #12024

Merged
merged 3 commits into from
Oct 7, 2022

Conversation

maipbui
Copy link
Contributor

@maipbui maipbui commented Sep 8, 2022

Signed-off-by: maipbui maibui@microsoft.com

Why I did it

subprocess.Popen() and subprocess.run() is used with shell=True, which is very dangerous for shell injection.
os - not secure against maliciously constructed input and dangerous if used to evaluate dynamic content

How I did it

Replace os by subprocess, remove shell=True
Remove unused functions

How to verify it

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: maipbui <maibui@microsoft.com>
@maipbui maipbui requested a review from qiluo-msft September 8, 2022 15:58
os.system('echo out > /sys/class/gpio/gpio502/direction')
os.system('echo 1 > /sys/class/gpio/gpio502/value')
with open('/sys/class/gpio/export', 'w') as file:
file.write('502')
Copy link
Collaborator

@qiluo-msft qiluo-msft Sep 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

502

Do you miss the trailing new line? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added \n, thank you.

Signed-off-by: maipbui <maibui@microsoft.com>
@maipbui
Copy link
Contributor Author

maipbui commented Sep 13, 2022

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft
Copy link
Collaborator

@LuiSzee @guxianghong @taochengyi @yangbashuang
Could you help review and verify?

@guxianghong
Copy link
Contributor

guxianghong commented Sep 20, 2022

@LuiSzee @guxianghong @taochengyi @yangbashuang Could you help review and verify?

Ok, we will review and verify it on centec platform.

@LuiSzee
Copy link
Contributor

LuiSzee commented Sep 21, 2022

subprocess.run not work on older version SONiC image, such as 201911

Python 2.7.17 (default, Jul  1 2022, 15:56:32)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run('sleep', '1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'

Signed-off-by: maipbui <maibui@microsoft.com>
@maipbui
Copy link
Contributor Author

maipbui commented Sep 21, 2022

subprocess.run not work on older version SONiC image, such as 201911

Python 2.7.17 (default, Jul  1 2022, 15:56:32)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.run('sleep', '1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'run'

@LuiSzee I changed it to subprocess.call(), thanks for your feedback.

@maipbui
Copy link
Contributor Author

maipbui commented Oct 6, 2022

@LuiSzee @guxianghong @taochengyi @yangbashuang Do you have any further comments?

@LuiSzee
Copy link
Contributor

LuiSzee commented Oct 7, 2022

@maipbui I have verified it on centec platform.

@maipbui maipbui marked this pull request as ready for review October 7, 2022 04:33
@maipbui maipbui merged commit 3cd9b2e into sonic-net:master Oct 7, 2022
@maipbui maipbui deleted the centec_sec branch October 7, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants