Skip to content

Commit 1e434e1

Browse files
committed
Merge branch 'V5-9-patches'
* V5-9-patches: Add test for NULL varbind set apps: snmpset: allow SET with NULL varbind for testing snmp_agent: disallow SET with NULL varbind
2 parents db41366 + be80410 commit 1e434e1

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

agent/snmp_agent.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,12 +3717,44 @@ netsnmp_handle_request(netsnmp_agent_session *asp, int status)
37173717
return 1;
37183718
}
37193719

3720+
static int
3721+
check_set_pdu_for_null_varbind(netsnmp_agent_session *asp)
3722+
{
3723+
int i;
3724+
netsnmp_variable_list *v = NULL;
3725+
3726+
for (i = 1, v = asp->pdu->variables; v != NULL; i++, v = v->next_variable) {
3727+
if (v->type == ASN_NULL) {
3728+
/*
3729+
* Protect SET implementations that do not protect themselves
3730+
* against wrong type.
3731+
*/
3732+
DEBUGMSGTL(("snmp_agent", "disallowing SET with NULL var for varbind %d\n", i));
3733+
asp->index = i;
3734+
return SNMP_ERR_WRONGTYPE;
3735+
}
3736+
}
3737+
return SNMP_ERR_NOERROR;
3738+
}
3739+
37203740
int
37213741
handle_pdu(netsnmp_agent_session *asp)
37223742
{
37233743
int status, inclusives = 0;
37243744
netsnmp_variable_list *v = NULL;
37253745

3746+
#ifndef NETSNMP_NO_WRITE_SUPPORT
3747+
/*
3748+
* Check for ASN_NULL in SET request
3749+
*/
3750+
if (asp->pdu->command == SNMP_MSG_SET) {
3751+
status = check_set_pdu_for_null_varbind(asp);
3752+
if (status != SNMP_ERR_NOERROR) {
3753+
return status;
3754+
}
3755+
}
3756+
#endif /* NETSNMP_NO_WRITE_SUPPORT */
3757+
37263758
/*
37273759
* for illegal requests, mark all nodes as ASN_NULL
37283760
*/

apps/snmpset.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ main(int argc, char *argv[])
182182
case 'x':
183183
case 'd':
184184
case 'b':
185+
case 'n': /* undocumented */
185186
#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
186187
case 'I':
187188
case 'U':
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
. ../support/simple_eval_tools.sh
4+
5+
HEADER SNMPv2c set of system.sysContact.0 with NULL varbind
6+
7+
SKIPIF NETSNMP_DISABLE_SET_SUPPORT
8+
SKIPIF NETSNMP_NO_WRITE_SUPPORT
9+
SKIPIF NETSNMP_DISABLE_SNMPV2C
10+
SKIPIFNOT USING_MIBII_SYSTEM_MIB_MODULE
11+
12+
#
13+
# Begin test
14+
#
15+
16+
# standard V2C configuration: testcomunnity
17+
snmp_write_access='all'
18+
. ./Sv2cconfig
19+
STARTAGENT
20+
21+
CAPTURE "snmpget -On $SNMP_FLAGS -c testcommunity -v 2c $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.2.1.1.4.0"
22+
23+
CHECK ".1.3.6.1.2.1.1.4.0 = STRING:"
24+
25+
CAPTURE "snmpset -On $SNMP_FLAGS -c testcommunity -v 2c $SNMP_TRANSPORT_SPEC:$SNMP_TEST_DEST$SNMP_SNMPD_PORT .1.3.6.1.2.1.1.4.0 n x"
26+
27+
CHECK "Reason: wrongType"
28+
29+
STOPAGENT
30+
31+
FINISHED

0 commit comments

Comments
 (0)