Skip to content

Fixed SNMPv3 msgUserName null terminator out-of-bounds write (#434) - #503

Open
Dev10-sys wants to merge 1 commit into
eclipse-threadx:devfrom
Dev10-sys:fix/snmpv3-user-name-null-terminator
Open

Dev10-sys wants to merge 1 commit into
eclipse-threadx:devfrom
Dev10-sys:fix/snmpv3-user-name-null-terminator

Conversation

@Dev10-sys

Copy link
Copy Markdown

Fixes #434

In addons/snmp/nxd_snmp.c, _nx_snmp_utility_octet_get was called with the full buffer size of nx_snmp_agent_v3_security_user_name (64 bytes), leaving no room for the null terminator. When a 64-byte username was received, writing the null terminator at index 64 wrote one byte past the array and corrupted the adjacent nx_snmp_agent_v3_security_user_name_size field, making the agent treat the request as an empty discovery packet. I fixed this by passing sizeof(agent_ptr -> nx_snmp_agent_v3_security_user_name) - 1 to _nx_snmp_utility_octet_get, which reserves one byte for the null terminator, safely keeping valid usernames within bounds and properly rejecting any username longer than 63 bytes.

…-threadx#434)

The SNMPv3 USM parser copies msgUserName into nx_snmp_agent_v3_security_user_name using _nx_snmp_utility_octet_get with sizeof(...) as the bound, and appends a null terminator at the returned size index. Because the array is 64 bytes (NX_SNMP_MAX_USER_NAME), a 64-byte user name writes a null terminator at index 64, which is one byte past the array.

In NX_SNMP_AGENT, nx_snmp_agent_v3_security_user_name_size immediately follows nx_snmp_agent_v3_security_user_name with no padding. On little-endian architectures, writing 0 to index 64 clears the low byte of the size field, corrupting the length from 64 to 0 and causing the agent to handle the request as an empty-username discovery packet.

_nx_snmp_utility_octet_get is now passed sizeof(...) - 1 at the call site, reserving room for the null terminator. Names exceeding 63 bytes are rejected as invalid packets, while valid names up to 63 bytes remain within bounds.

Signed-off-by: Dev dev <kalpanagola9897@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant