HomeFreeBSD

libbsnmp: make snmp_parse_server() more robust when lacking info

Description

libbsnmp: make snmp_parse_server() more robust when lacking info

Per documentation snmp_parse_server() has all 4 components optional. We
want inputs like "udp::", "udp6::", "stream::" work with local default
sockets and even degenerate case of "" shall end with defaults instead of
a failure.

While here make the parser more robust. Make all parser helpers to behave
the same way: on successful return they are responsible to update both
start & end of matched substring and return next characater to parse.
This eliminates special handling of IPv6 and port parser that used to need
to skip a character, and thus eliminates unchecked step forward in
snmp_parse_server() itself. Additionally:

  • use strchr(3) instead of own cycle
  • INET_ADDRSTRLEN includes space for NUL character
  • INET6_ADDRSTRLEN includes both the scope and NUL character
  • prefer sizeof() comparison instead of preprocessor define repetitive use

Reviewed by: harti
Differential Revision: https://reviews.freebsd.org/D51072

Details

Provenance
glebiusAuthored on Jul 25 2025, 8:10 PM
Reviewer
harti
Differential Revision
D51072: libbsnmp: make snmp_parse_server() more robust when lacking info
Parents
rG777123969db5: libbsnmp: make binding of client UNIX socket optional and configurable
Branches
Unknown
Tags
Unknown