-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[device/centec] Replace os.system and remove subprocess with shell=Tr…
…ue (#12024) 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
- Loading branch information
Showing
12 changed files
with
52 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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,11 +1,13 @@ | ||
#!/usr/bin/python | ||
import os | ||
|
||
def main(): | ||
# reboot the system | ||
os.system('echo 502 > /sys/class/gpio/export') | ||
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\n') | ||
with open('/sys/class/gpio/gpio502/direction', 'w') as file: | ||
file.write('out\n') | ||
with open('/sys/class/gpio/gpio502/value', 'w') as file: | ||
file.write('1\n') | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,11 +1,13 @@ | ||
#!/usr/bin/python | ||
import os | ||
|
||
def main(): | ||
# reboot the system | ||
os.system('echo 502 > /sys/class/gpio/export') | ||
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\n') | ||
with open('/sys/class/gpio/gpio502/direction', 'w') as file: | ||
file.write('out\n') | ||
with open('/sys/class/gpio/gpio502/value', 'w') as file: | ||
file.write('1\n') | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,12 +1,12 @@ | ||
#!/usr/bin/python | ||
import os | ||
import subprocess | ||
|
||
def main(): | ||
# reboot the system | ||
os.system('modprobe i2c-dev') | ||
os.system('i2cset -y 0 0x36 0x23 0x0') | ||
os.system('sleep 1') | ||
os.system('i2cset -y 0 0x36 0x23 0x3') | ||
subprocess.call(['modprobe', 'i2c-dev']) | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0x0']) | ||
subprocess.call(['sleep', '1']) | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0x3']) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,11 +1,13 @@ | ||
#!/usr/bin/python | ||
import os | ||
|
||
def main(): | ||
# reboot the system | ||
os.system('echo 502 > /sys/class/gpio/export') | ||
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\n') | ||
with open('/sys/class/gpio/gpio502/direction', 'w') as file: | ||
file.write('out\n') | ||
with open('/sys/class/gpio/gpio502/value', 'w') as file: | ||
file.write('1\n') | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,15 +1,15 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import subprocess | ||
import time | ||
|
||
def main(): | ||
os.system('hwclock -w -f /dev/rtc1') | ||
subprocess.call(['hwclock', '-w', '-f', '/dev/rtc1']) | ||
time.sleep(1) | ||
|
||
os.system('i2cset -y 0 0x36 0x23 0') | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0']) | ||
time.sleep(1) | ||
os.system('i2cset -y 0 0x36 0x23 1') | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '1']) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 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 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,15 +1,15 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import subprocess | ||
import time | ||
|
||
def main(): | ||
os.system('hwclock -w -f /dev/rtc1') | ||
subprocess.call(['hwclock', '-w', '-f', '/dev/rtc1']) | ||
time.sleep(1) | ||
|
||
os.system('i2cset -y 0 0x36 0x23 0') | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '0']) | ||
time.sleep(1) | ||
os.system('i2cset -y 0 0x36 0x23 1') | ||
subprocess.call(['i2cset', '-y', '0', '0x36', '0x23', '1']) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 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 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 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