From 1eb9016fb52bf2f73c3b9ccf1902cd5d72ca3f4c Mon Sep 17 00:00:00 2001 From: martijn Date: Tue, 24 Oct 2023 13:46:11 +0000 Subject: [PATCH] Fix appl_register() when called with range_subid set to !0. OK tb@ --- usr.sbin/snmpd/application.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/usr.sbin/snmpd/application.c b/usr.sbin/snmpd/application.c index 33bb8d7ceba..77826001110 100644 --- a/usr.sbin/snmpd/application.c +++ b/usr.sbin/snmpd/application.c @@ -1,4 +1,4 @@ -/* $OpenBSD: application.c,v 1.18 2023/10/24 13:28:11 martijn Exp $ */ +/* $OpenBSD: application.c,v 1.19 2023/10/24 13:46:11 martijn Exp $ */ /* * Copyright (c) 2021 Martijn van Duren @@ -347,28 +347,29 @@ appl_register(const char *ctxname, uint32_t timeout, uint8_t priority, backend->ab_name, oidbuf); return APPL_ERROR_PARSEERROR; } - if (range_subid > oid->bo_n) { + + if (range_subid == 0) + return appl_region(ctx, timeout, priority, oid, instance, + subtree, backend); + + range_subid--; + if (range_subid >= oid->bo_n) { log_warnx("%s: Can't register %s: range_subid too large", backend->ab_name, oidbuf); return APPL_ERROR_PARSEERROR; } - if (range_subid != 0 && oid->bo_id[range_subid] >= upper_bound) { - log_warnx("%s: Can't register %s: upper bound smaller or equal " - "to range_subid", backend->ab_name, oidbuf); + if (oid->bo_id[range_subid] > upper_bound) { + log_warnx("%s: Can't register %s: upper bound smaller than " + "range_subid", backend->ab_name, oidbuf); return APPL_ERROR_PARSEERROR; } - if (range_subid != 0) - lower_bound = oid->bo_id[range_subid]; - - if (range_subid == 0) - return appl_region(ctx, timeout, priority, oid, instance, - subtree, backend); + lower_bound = oid->bo_id[range_subid]; do { if ((error = appl_region(ctx, timeout, priority, oid, instance, subtree, backend)) != APPL_ERROR_NOERROR) goto fail; - } while (oid->bo_id[range_subid] != upper_bound); + } while (oid->bo_id[range_subid]++ != upper_bound); if ((error = appl_region(ctx, timeout, priority, oid, instance, subtree, backend)) != APPL_ERROR_NOERROR) goto fail; -- 2.20.1