net-snmp: add early return when Mode is unset
authorEric McDonald <redacted>
Sat, 7 Mar 2026 21:45:22 +0000 (13:45 -0800)
committerFlorian Eckert <redacted>
Wed, 11 Mar 2026 08:07:04 +0000 (09:07 +0100)
snmpd_access_default_add, snmpd_access_HostName_add, and
snmpd_access_HostIP_add would write unintended output to the
config file if the Mode option is not specified. Add an early
return to each function to prevent writing in that case.

This is a breaking change for configs where Mode is unset.
Previously, an empty Mode option would result in a malformed
directive with a leading space and no guaranteed newline, the
exact form of which depended on the values of other options.
Now, no directive is written.

Signed-off-by: Eric McDonald <redacted>
net/net-snmp/files/snmpd.init

index 78df7c9a2bda60386c9eb9afa741471304f48f07..bc675792d995f83c334639ff07e32e6dd7010463 100644 (file)
@@ -130,6 +130,7 @@ snmpd_trap_ip_add() {
 snmpd_access_default_add() {
        local cfg="$1"
        config_get mode "$cfg" Mode
+       [ -n "$mode" ] || return 0
        config_get community "$cfg" CommunityName
        config_get oidrestrict "$cfg" RestrictOID
        config_get oid "$cfg" RestrictedOID
@@ -142,6 +143,7 @@ snmpd_access_HostName_add() {
        local cfg="$1"
        config_get hostname "$cfg" HostName
        config_get mode "$cfg" Mode
+       [ -n "$mode" ] || return 0
        config_get community "$cfg" CommunityName
        config_get oidrestrict "$cfg" RestrictOID
        config_get oid "$cfg" RestrictedOID
@@ -155,6 +157,7 @@ snmpd_access_HostIP_add() {
        config_get host_ip "$cfg" HostIP
        config_get ip_mask "$cfg" IPMask
        config_get mode "$cfg" Mode
+       [ -n "$mode" ] || return 0
        config_get community "$cfg" CommunityName
        config_get oidrestrict "$cfg" RestrictOID
        config_get oid "$cfg" RestrictedOID
git clone https://git.99rst.org/PROJECT