From 253352b645fc4a41f016554b8b576e7cb4a43393 Mon Sep 17 00:00:00 2001 From: martijn Date: Tue, 24 Oct 2023 13:28:11 +0000 Subject: [PATCH] Always check if the context is available inside appl_agentx_recv(). Not every PDU goes through application.c. OK tb@ --- usr.sbin/snmpd/application.c | 4 ++-- usr.sbin/snmpd/application.h | 4 +++- usr.sbin/snmpd/application_agentx.c | 8 +++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/usr.sbin/snmpd/application.c b/usr.sbin/snmpd/application.c index dd92864786d..33bb8d7ceba 100644 --- a/usr.sbin/snmpd/application.c +++ b/usr.sbin/snmpd/application.c @@ -1,4 +1,4 @@ -/* $OpenBSD: application.c,v 1.17 2022/12/20 20:04:55 martijn Exp $ */ +/* $OpenBSD: application.c,v 1.18 2023/10/24 13:28:11 martijn Exp $ */ /* * Copyright (c) 2021 Martijn van Duren @@ -175,7 +175,7 @@ appl_shutdown(void) } } -static struct appl_context * +struct appl_context * appl_context(const char *name, int create) { struct appl_context *ctx; diff --git a/usr.sbin/snmpd/application.h b/usr.sbin/snmpd/application.h index 8b2c5678c3a..39e7b5fc410 100644 --- a/usr.sbin/snmpd/application.h +++ b/usr.sbin/snmpd/application.h @@ -1,4 +1,4 @@ -/* $OpenBSD: application.h,v 1.5 2022/09/01 14:34:17 martijn Exp $ */ +/* $OpenBSD: application.h,v 1.6 2023/10/24 13:28:11 martijn Exp $ */ /* * Copyright (c) 2021 Martijn van Duren @@ -88,6 +88,7 @@ struct appl_varbind { struct snmp_message; enum snmp_version; struct appl_backend; +struct appl_context; struct appl_backend_functions { void (*ab_close)(struct appl_backend *, enum appl_close_reason); @@ -121,6 +122,7 @@ struct appl_backend { void appl(void); void appl_init(void); void appl_shutdown(void); +struct appl_context *appl_context(const char *, int); enum appl_error appl_register(const char *, uint32_t, uint8_t, struct ber_oid *, int, int, uint8_t, uint32_t, struct appl_backend *); enum appl_error appl_unregister(const char *, uint8_t, struct ber_oid *, diff --git a/usr.sbin/snmpd/application_agentx.c b/usr.sbin/snmpd/application_agentx.c index 3a67f9dc0f1..81b37bd9280 100644 --- a/usr.sbin/snmpd/application_agentx.c +++ b/usr.sbin/snmpd/application_agentx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: application_agentx.c,v 1.7 2023/10/24 12:57:40 martijn Exp $ */ +/* $OpenBSD: application_agentx.c,v 1.8 2023/10/24 13:28:11 martijn Exp $ */ /* * Copyright (c) 2022 Martijn van Duren * @@ -370,6 +370,12 @@ appl_agentx_recv(int fd, short event, void *cookie) error = APPL_ERROR_PARSEERROR; goto fail; } + if (appl_context(pdu->ap_context.aos_string, 0) == NULL) { + log_warnx("%s: %s: Unsupported context", + name, ax_pdutype2string(pdu->ap_header.aph_flags)); + error = APPL_ERROR_UNSUPPORTEDCONTEXT; + goto fail; + } } switch (pdu->ap_header.aph_type) { case AX_PDU_TYPE_OPEN: -- 2.20.1