Re: snmpd [8/16]: Fix range handling with appl_register

2023-10-24 Thread Theo Buehler
On Tue, Oct 17, 2023 at 03:08:00PM +0200, Martijn van Duren wrote:
> Right now (un)registering a region with range_subid set to !0 will
> fail. Apparently nothing in the wild uses this, but let's fix it.
> 
> This is the register part.

ok tb



snmpd [8/16]: Fix range handling with appl_register

2023-10-17 Thread Martijn van Duren
Right now (un)registering a region with range_subid set to !0 will
fail. Apparently nothing in the wild uses this, but let's fix it.

This is the register part.

OK?

martijn@

diff --git a/application.c b/application.c
index a02260b..f8709b8 100644
--- a/application.c
+++ b/application.c
@@ -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;