Skip to content

Commit

Permalink
[broadcom] Replace popen function (#12106)
Browse files Browse the repository at this point in the history
Signed-off-by: maipbui <[email protected]>
#### Why I did it
`os` - not secure against maliciously constructed input and dangerous if used to evaluate dynamic content.
#### How I did it
`os` - use with `subprocess`
#### How to verify it
  • Loading branch information
maipbui authored and pull[bot] committed Mar 15, 2024
1 parent e4ddbfc commit f6cdbb4
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import struct
from ctypes import *
import os
from sonic_py_common.general import getstatusoutput_noshell_pipe

TLV_CODE_PRODUCT_NAME = 0x21
TLV_CODE_SERIAL_NUMBER = 0x23
Expand Down Expand Up @@ -71,7 +72,7 @@ def main():
tlvinfo_data = TLVINFO_DATA()
tlvinfo_data.add_tlv_str(TLV_CODE_SERIAL_NUMBER, 'S/N')

onie_machine = os.popen("cat /host/machine.conf | grep 'onie_machine=' | sed 's/onie_machine=//'").read().strip()
_, onie_machine = getstatusoutput_noshell_pipe(["cat", "/host/machine.conf"], ["grep", 'onie_machine='], ["sed", 's/onie_machine=//'])
if onie_machine == 'bcm_xlr':
tlvinfo_data.add_tlv_str(TLV_CODE_PRODUCT_NAME, 'BCM9COMX2XMC')
else:
Expand All @@ -83,11 +84,11 @@ def main():
eth0_mac = eth0_mac_str.split(':')
tlvinfo_data.add_tlv_mac(TLV_CODE_MAC_BASE, eth0_mac)

brcm_dev = os.popen("lspci | grep -m1 'Ethernet controller: Broadcom ' | grep 'Device' | sed 's/(.*//' | awk '{print $NF}'").read().strip()
_, brcm_dev = getstatusoutput_noshell_pipe(["lspci"], ["grep", "-m1", 'Ethernet controller: Broadcom '], ["grep", 'Device'], ["sed", 's/(.*//'], ["awk", '{print $NF}'])
if brcm_dev == 'b960':
tlvinfo_data.add_tlv_str(TLV_CODE_PLATFORM_NAME, 'BCM956960K')

onie_version = os.popen("cat /host/machine.conf | grep 'onie_version' | sed 's/onie_version=//'").read().strip()
onie_version = getstatusoutput_noshell_pipe(["cat", "/host/machine.conf"], ["grep", 'onie_version'], ["sed", 's/onie_version=//'])
tlvinfo_data.add_tlv_str(TLV_CODE_ONIE_VERSION, onie_version)

tlvinfo_header.totallen = len(tlvinfo_data.dump())+4;
Expand Down

0 comments on commit f6cdbb4

Please sign in to comment.