Description: VACM: Fix out-of-bounds reads and integer overflows
 CVE-2026-138295
 .
 In sec2group_parse_oid(), change oidLen <= 0 into oidLen < 2 to
 guarantee that oidIndex[1] may be read.
 .
 In access_parse_oid(), change oidLen <= 0 into oidLen < 4 to ensure that
 the following expressions stay inside the array bounds: oidIndex[0],
 oidIndex[groupNameL + 1], oidIndex[groupNameL + contextPrefixL + 2] and
 oidIndex[groupNameL + contextPrefixL + 3].
 .
 In view_parse_oid(), check whether viewNameL < oidLen before
 subtracting these two variables. Remove the subtreeL < 0 test because it
 is guaranteed that subtreeL >= 0.
Author: Bart Van Assche <bvanassche@acm.org>
Origin: upstream, https://github.com/net-snmp/net-snmp/commit/e96e212a101d4c4beb51cf7cd7d89f1e342f9eed
Bug-Debian: https://bugs.debian.org/1155726
Reviewed-by: Craig Small <csmall@debian.org>
Last-Update: 2026-11-29
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/agent/mibgroup/mibII/vacm_vars.c
+++ b/agent/mibgroup/mibII/vacm_vars.c
@@ -683,17 +683,17 @@
 sec2group_parse_oid(oid * oidIndex, size_t oidLen,
                     int *model, unsigned char **name, size_t * nameLen)
 {
-    int             nameL;
-    int             i;
+    oid             nameL;
+    size_t          i;
 
     /*
      * first check the validity of the oid 
      */
-    if ((oidLen <= 0) || (!oidIndex)) {
+    if (oidLen < 2 || !oidIndex) {
         return 1;
     }
     nameL = oidIndex[1];        /* the initial name length */
-    if ((int) oidLen != nameL + 2) {
+    if (oidLen != nameL + 2) {
         return 1;
     }
 
@@ -987,21 +987,21 @@
                  unsigned char **contextPrefix, size_t * contextPrefixLen,
                  int *model, int *level)
 {
-    int             groupNameL, contextPrefixL;
-    int             i;
+    oid             groupNameL, contextPrefixL;
+    size_t          i;
 
     /*
      * first check the validity of the oid 
      */
-    if ((oidLen <= 0) || (!oidIndex)) {
+    if (oidLen < 4 || !oidIndex) {
         return 1;
     }
     groupNameL = oidIndex[0];
-    if ((groupNameL + 1) > (int) oidLen) {
+    if (groupNameL >= oidLen || oidLen - groupNameL < 4) {
         return 1;
     }
     contextPrefixL = oidIndex[groupNameL + 1];  /* the initial name length */
-    if ((int) oidLen != groupNameL + contextPrefixL + 4) {
+    if (oidLen - groupNameL - 4 != contextPrefixL) {
         return 1;
     }
 
@@ -1468,15 +1468,18 @@
                unsigned char **viewName, size_t * viewNameLen,
                oid ** subtree, size_t * subtreeLen)
 {
-    int             viewNameL, subtreeL, i;
+    size_t          viewNameL, subtreeL, i;
 
     /*
      * first check the validity of the oid 
      */
-    if ((oidLen <= 0) || (!oidIndex)) {
+    if (oidLen < 1 || !oidIndex) {
         return SNMP_ERR_INCONSISTENTNAME;
     }
     viewNameL = oidIndex[0];
+    if (viewNameL >= oidLen) {
+        return SNMP_ERR_INCONSISTENTNAME;
+    }
     subtreeL = oidLen - viewNameL - 1;  /* the initial name length */
 
     /*
@@ -1486,10 +1489,6 @@
         return SNMP_ERR_RESOURCEUNAVAILABLE;
     }
 
-    if (subtreeL < 0) {
-        return SNMP_ERR_NOCREATION;
-    }
-
     *viewName = (unsigned char *) malloc(viewNameL + 1);
 
     if (*viewName == NULL) {
