From dae64e9e225d0c4320fe266e6b924a1630222416 Mon Sep 17 00:00:00 2001 From: martijn Date: Sun, 29 Oct 2023 11:15:09 +0000 Subject: [PATCH] Add a regress test to make sure that agentx responses equal to searchrange.end are rejected. --- regress/usr.sbin/snmpd/Makefile | 3 +- regress/usr.sbin/snmpd/backend.c | 56 ++++++++++++++++++++++++++ regress/usr.sbin/snmpd/regress.h | 1 + regress/usr.sbin/snmpd/snmpd_regress.c | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/regress/usr.sbin/snmpd/Makefile b/regress/usr.sbin/snmpd/Makefile index 18f158c627d..713cb32602e 100644 --- a/regress/usr.sbin/snmpd/Makefile +++ b/regress/usr.sbin/snmpd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2023/10/27 10:26:20 martijn Exp $ +# $OpenBSD: Makefile,v 1.7 2023/10/29 11:15:09 martijn Exp $ # Regress tests for snmpd PROG = snmpd_regress @@ -170,6 +170,7 @@ BACKEND_TARGETS+= backend_getnext_stale BACKEND_TARGETS+= backend_getnext_inclusive_backwards BACKEND_TARGETS+= backend_getnext_toofew BACKEND_TARGETS+= backend_getnext_toomany +BACKEND_TARGETS+= backend_getnext_response_equal_end BACKEND_TARGETS+= backend_getbulk_nonrep_zero_maxrep_one BACKEND_TARGETS+= backend_getbulk_nonrep_zero_maxrep_two BACKEND_TARGETS+= backend_getbulk_nonrep_one_maxrep_one diff --git a/regress/usr.sbin/snmpd/backend.c b/regress/usr.sbin/snmpd/backend.c index 52f19e49b01..f4957ff56ae 100644 --- a/regress/usr.sbin/snmpd/backend.c +++ b/regress/usr.sbin/snmpd/backend.c @@ -2632,6 +2632,62 @@ backend_getnext_toomany(void) varbind, 2); } +void +backend_getnext_response_equal_end(void) +{ + struct sockaddr_storage ss; + struct sockaddr *sa = (struct sockaddr *)&ss; + socklen_t salen; + int snmp_s, ax_s; + uint32_t sessionid1, sessionid2; + struct varbind varbind[] = { + { + .type = TYPE_NULL, + .name = OID_STRUCT(MIB_BACKEND_GETNEXT, 26), + .data.int32 = 1 + }, + }; + struct searchrange searchrange[] = { + { + .start = OID_STRUCT(MIB_BACKEND_GETNEXT, 26), + .end = OID_STRUCT(MIB_BACKEND_GETNEXT, 26, 1, 1) + }, + }; + int32_t requestid; + char buf[1024]; + size_t n; + + ax_s = agentx_connect(axsocket); + sessionid1 = agentx_open(ax_s, 0, 0, + OID_ARG(MIB_SUBAGENT_BACKEND_GETNEXT, 26, 1), + "backend_getnext_end_equal.1"); + sessionid2 = agentx_open(ax_s, 0, 0, + OID_ARG(MIB_SUBAGENT_BACKEND_GETNEXT, 26, 2), + "backend_getnext_end_equal.2"); + agentx_register(ax_s, sessionid1, 0, 0, 127, 0, + OID_ARG(MIB_BACKEND_GETNEXT, 26), 0); + agentx_register(ax_s, sessionid2, 0, 0, 127, 0, + OID_ARG(MIB_BACKEND_GETNEXT, 26, 1, 1), 0); + + salen = snmp_resolve(SOCK_DGRAM, hostname, servname, sa); + snmp_s = snmp_connect(SOCK_DGRAM, sa, salen); + requestid = snmpv2_getnext(snmp_s, community, 0, varbind, 1); + + /* Fool agentx_getnext_handle() */ + varbind[0].name.subid[varbind[0].name.n_subid++] = 1; + varbind[0].type = TYPE_INTEGER; + n = agentx_read(ax_s, buf, sizeof(buf), 1000); + agentx_getnext_handle(__func__, buf, n, 0, sessionid1, searchrange, + varbind, 1); + varbind[0].name = searchrange[0].end; + agentx_response(ax_s, buf, NOERROR, 0, varbind, 1); + varbind[0].type = TYPE_NULL; + varbind[0].name = OID_STRUCT(MIB_BACKEND_GETNEXT, 26), + + snmpv2_response_validate(snmp_s, 1000, community, requestid, GENERR, 1, + varbind, 1); +} + void backend_getbulk_nonrep_zero_maxrep_one(void) { diff --git a/regress/usr.sbin/snmpd/regress.h b/regress/usr.sbin/snmpd/regress.h index 9e4c0fda540..20b6292ea40 100644 --- a/regress/usr.sbin/snmpd/regress.h +++ b/regress/usr.sbin/snmpd/regress.h @@ -293,6 +293,7 @@ void backend_getnext_stale(void); void backend_getnext_inclusive_backwards(void); void backend_getnext_toofew(void); void backend_getnext_toomany(void); +void backend_getnext_response_equal_end(void); void backend_getbulk_nonrep_zero_maxrep_one(void); void backend_getbulk_nonrep_zero_maxrep_two(void); void backend_getbulk_nonrep_one_maxrep_one(void); diff --git a/regress/usr.sbin/snmpd/snmpd_regress.c b/regress/usr.sbin/snmpd/snmpd_regress.c index bb2235ee837..2a56da34aa6 100644 --- a/regress/usr.sbin/snmpd/snmpd_regress.c +++ b/regress/usr.sbin/snmpd/snmpd_regress.c @@ -143,6 +143,7 @@ const struct { { "backend_getnext_inclusive_backwards", backend_getnext_inclusive_backwards }, { "backend_getnext_toofew", backend_getnext_toofew }, { "backend_getnext_toomany", backend_getnext_toomany }, + { "backend_getnext_response_equal_end", backend_getnext_response_equal_end }, { "backend_getbulk_nonrep_zero_maxrep_one", backend_getbulk_nonrep_zero_maxrep_one }, { "backend_getbulk_nonrep_zero_maxrep_two", backend_getbulk_nonrep_zero_maxrep_two }, { "backend_getbulk_nonrep_one_maxrep_one", backend_getbulk_nonrep_one_maxrep_one }, -- 2.20.1