Skip to content

Treat DHCP-provided SNMP community values as data - #29287

Open
ashutosh-agrawal wants to merge 1 commit into
sonic-net:masterfrom
ashutosh-agrawal:handle-dhcp-snmp-community-as-data
Open

Treat DHCP-provided SNMP community values as data#29287
ashutosh-agrawal wants to merge 1 commit into
sonic-net:masterfrom
ashutosh-agrawal:handle-dhcp-snmp-community-as-data

Conversation

@ashutosh-agrawal

Copy link
Copy Markdown
Member

Why I did it

The dhclient exit hook currently inserts DHCP option 224 directly into a sed program. Since the option comes from the DHCP response, characters in the value can change what sed does instead of remaining part of the SNMP community string.

Work item tracking
  • Microsoft ADO (number only): N/A

How I did it

  • Validate the supplied value using the same length and character restrictions as the SNMP_COMMUNITY YANG key.
  • Write the community as a quoted YAML value using printf, without placing it in a shell or sed program.
  • Replace snmp.yml through a temporary file and preserve the existing file ownership and permissions.
  • Add regression coverage for valid punctuation, malformed values, replacement, append, and new-file cases.

How to verify it

dash -n files/dhcp/snmpcommunity
dash -n files/dhcp/tests/test_snmpcommunity.sh
files/dhcp/tests/test_snmpcommunity.sh
shellcheck -x -s dash -e SC1091,SC2154 \
    files/dhcp/snmpcommunity \
    files/dhcp/tests/test_snmpcommunity.sh
git diff --check

All checks passed.

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

No backport requested.

Tested branch

  • master

Test result

The focused shell regression test passed on master. It verifies that shell and sed metacharacters remain data while malformed community values are rejected.

Description for the changelog

Safely handle DHCP-provided SNMP community values when updating snmp.yml.

Link to config_db schema for YANG module changes

N/A

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

Signed-off-by: Ashutosh Agrawal <ashu@cisco.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants