new file mode 100644
@@ -0,0 +1,110 @@
+From b5398cafe301616d39bf6fd3df86b456ee51011d Mon Sep 17 00:00:00 2001
+From: Bart Van Assche <bvanassche@acm.org>
+Date: Thu, 11 Jun 2026 13:03:22 -0700
+Subject: [PATCH] snmpd: VACM: Fix out-of-bounds reads and integer overflows
+
+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.
+
+(cherry picked from commit e96e212a101d4c4beb51cf7cd7d89f1e342f9eed)
+CVE: CVE-2026-138295
+Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/e96e212a101d4c4beb51cf7cd7d89f1e342f9eed]
+Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
+---
+ agent/mibgroup/mibII/vacm_vars.c | 29 ++++++++++++++---------------
+ 1 file changed, 14 insertions(+), 15 deletions(-)
+
+diff --git a/agent/mibgroup/mibII/vacm_vars.c b/agent/mibgroup/mibII/vacm_vars.c
+index ad6f6ddf9..43ca491a5 100644
+--- a/agent/mibgroup/mibII/vacm_vars.c
++++ b/agent/mibgroup/mibII/vacm_vars.c
+@@ -683,17 +683,17 @@ int
+ 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 @@ access_parse_oid(oid * oidIndex, size_t oidLen,
+ 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 @@ view_parse_oid(oid * oidIndex, size_t oidLen,
+ 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 @@ view_parse_oid(oid * oidIndex, size_t oidLen,
+ return SNMP_ERR_RESOURCEUNAVAILABLE;
+ }
+
+- if (subtreeL < 0) {
+- return SNMP_ERR_NOCREATION;
+- }
+-
+ *viewName = (unsigned char *) malloc(viewNameL + 1);
+
+ if (*viewName == NULL) {
new file mode 100644
@@ -0,0 +1,241 @@
+From 1bf1e257d0920f6cb983d9cfba9446a57feeed3e Mon Sep 17 00:00:00 2001
+From: Bart Van Assche <bvanassche@acm.org>
+Date: Tue, 11 Aug 2026 23:14:28 +0000
+Subject: [PATCH] testing: Add regression unit tests for VACM OID parsing and
+ display hints
+
+Add unit test coverage for memory safety defects reported in VACM OID
+parsing functions and numeric DISPLAY-HINT formatting:
+
+- In testing/fulltests/unit-tests/T025sprint_realloc_octet_string_clib.c,
+ extend test suite with multi-byte numeric display hints (2d, 4d, 2x,
+ 2o, 2d-2d) where data length is shorter than hint field width.
+ This verifies that sprint_realloc_octet_string() bounds reading
+ against remaining buffer length rather than over-reading (F-4/F-3).
+
+- In testing/fulltests/unit-tests/T031vacm_parse_oid_clib.c, add unit
+ tests for access_parse_oid(), view_parse_oid(), and
+ sec2group_parse_oid(). Test rejection of 0xFFFFFFFF OID length
+ sub-identifiers, lengths exceeding remaining OID array size,
+ sub-identifier values greater than 255 in string fields,
+ zero/short lengths, and NULL pointers, as well as successful
+ parsing of valid table entry OIDs (F-1 and F-5).
+
+These tests fix issues detected by Michalis Vasileiadis and his Hacker Bob
+v2.0.1 software, an open-source autonomous source-audit framework. See
+also https://github.com/vmihalis/hacker-bob. The underlying AI model is
+Claude Opus 4.8.
+
+CVE: CVE-2026-138295
+Upstream-Status: Backport [https://github.com/net-snmp/net-snmp/commit/11a86c9aeb31f3cf07d6cc9259fcae34de6b3474]
+
+Dropped change to T025sprint_realloc_octet_string_clib.c which was added
+by commit[1] after v5.9.5.2
+
+[1] https://github.com/net-snmp/net-snmp/commit/4d779b69087f3e082fa3293f3b6f513bac2f5e7a
+
+Signed-off-by: Ankur Tyagi <ankur.tyagi85@gmail.com>
+---
+ .../unit-tests/T031vacm_parse_oid_clib.c | 193 ++++++++++++++++++
+ 1 file changed, 193 insertions(+)
+ create mode 100644 testing/fulltests/unit-tests/T031vacm_parse_oid_clib.c
+
+diff --git a/testing/fulltests/unit-tests/T031vacm_parse_oid_clib.c b/testing/fulltests/unit-tests/T031vacm_parse_oid_clib.c
+new file mode 100644
+index 000000000..cf0d0ea0e
+--- /dev/null
++++ b/testing/fulltests/unit-tests/T031vacm_parse_oid_clib.c
+@@ -0,0 +1,193 @@
++/* HEADER Testing VACM OID parsing (access_parse_oid, view_parse_oid, sec2group_parse_oid) */
++
++#include <net-snmp/net-snmp-includes.h>
++#include <net-snmp/agent/net-snmp-agent-includes.h>
++#include <net-snmp/agent/all_helpers.h>
++#include <mibII/vacm_vars.h>
++
++#if !defined(NETSNMP_NO_WRITE_SUPPORT) && defined(HAVE_LIBNL3)
++
++/* =========================================================================
++ * Test access_parse_oid() (Finding F-1 and edge cases)
++ * ========================================================================= */
++{
++ unsigned char *groupName = NULL, *contextPrefix = NULL;
++ size_t groupNameLen = 0, contextPrefixLen = 0;
++ int model = 0, level = 0;
++ int res;
++
++ /*
++ * Finding F-1: 0xFFFFFFFF in oidIndex[0] and oidIndex[1] with short oidLen.
++ * Must be rejected without buffer underwrite or out-of-bounds access.
++ */
++ oid f1_oid[] = { 0xFFFFFFFFUL, 0xFFFFFFFFUL };
++ res = access_parse_oid(f1_oid, sizeof(f1_oid) / sizeof(f1_oid[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res != 0, "access_parse_oid with F-1 truncated OID rejected");
++
++ /* Large groupName length exceeding oidLen */
++ oid large_gn_oid[] = { 0xFFFFFFFFUL, 0, 0, 0, 0, 0 };
++ res = access_parse_oid(large_gn_oid, sizeof(large_gn_oid) / sizeof(large_gn_oid[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res != 0, "access_parse_oid with large groupName length rejected");
++
++ /* Large contextPrefix length exceeding oidLen */
++ oid large_cp_oid[] = { 1, 'a', 0xFFFFFFFFUL, 0, 0, 0 };
++ res = access_parse_oid(large_cp_oid, sizeof(large_cp_oid) / sizeof(large_cp_oid[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res != 0, "access_parse_oid with large contextPrefix length rejected");
++
++ /* Short oidLen / NULL pointer checks */
++ res = access_parse_oid(NULL, 10, &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen, &model, &level);
++ OK(res != 0, "access_parse_oid with NULL oidIndex rejected");
++
++ res = access_parse_oid(f1_oid, 0, &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen, &model, &level);
++ OK(res != 0, "access_parse_oid with oidLen=0 rejected");
++
++ res = access_parse_oid(f1_oid, 3, &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen, &model, &level);
++ OK(res != 0, "access_parse_oid with oidLen=3 rejected");
++
++ /* Character > 255 in groupName */
++ oid oob_char_gn[] = { 1, 300, 0, 3, 1 };
++ res = access_parse_oid(oob_char_gn, sizeof(oob_char_gn) / sizeof(oob_char_gn[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res != 0, "access_parse_oid with groupName char > 255 rejected");
++
++ /* Character > 255 in contextPrefix */
++ oid oob_char_cp[] = { 1, 'a', 1, 300, 3, 1 };
++ res = access_parse_oid(oob_char_cp, sizeof(oob_char_cp) / sizeof(oob_char_cp[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res != 0, "access_parse_oid with contextPrefix char > 255 rejected");
++
++ /* Valid access entry OID parsing */
++ oid valid_access_oid[] = { 3, 'g', 'r', 'p', 3, 'c', 't', 'x', 3, 1 };
++ groupName = NULL;
++ contextPrefix = NULL;
++ res = access_parse_oid(valid_access_oid,
++ sizeof(valid_access_oid) / sizeof(valid_access_oid[0]),
++ &groupName, &groupNameLen,
++ &contextPrefix, &contextPrefixLen,
++ &model, &level);
++ OK(res == 0, "access_parse_oid with valid OID succeeded");
++ OK(groupName != NULL && groupNameLen == 3 && strcmp((char *)groupName, "grp") == 0,
++ "access_parse_oid parsed groupName correctly");
++ OK(contextPrefix != NULL && contextPrefixLen == 3 && strcmp((char *)contextPrefix, "ctx") == 0,
++ "access_parse_oid parsed contextPrefix correctly");
++ OK(model == 3, "access_parse_oid parsed model correctly");
++ OK(level == 1, "access_parse_oid parsed level correctly");
++ free(groupName);
++ free(contextPrefix);
++}
++
++/* =========================================================================
++ * Test view_parse_oid() (Finding F-5 and edge cases)
++ * ========================================================================= */
++{
++ unsigned char *viewName = NULL;
++ size_t viewNameLen = 0, subtreeLen = 0;
++ oid *subtree = NULL;
++ int res;
++
++ /*
++ * Finding F-5: 0xFFFFFFFF in oidIndex[0] with short oidLen.
++ * Must be rejected without buffer underwrite or out-of-bounds access.
++ */
++ oid f5_oid[] = { 0xFFFFFFFFUL };
++ res = view_parse_oid(f5_oid, sizeof(f5_oid) / sizeof(f5_oid[0]),
++ &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with F-5 truncated OID rejected");
++
++ /* Large viewName length exceeding oidLen */
++ oid large_vn_oid[] = { 0xFFFFFFFFUL, 1, 3, 6, 1 };
++ res = view_parse_oid(large_vn_oid, sizeof(large_vn_oid) / sizeof(large_vn_oid[0]),
++ &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with large viewName length rejected");
++
++ /* Short oidLen / NULL pointer checks */
++ res = view_parse_oid(NULL, 10, &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with NULL oidIndex rejected");
++
++ res = view_parse_oid(f5_oid, 0, &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with oidLen=0 rejected");
++
++ /* viewNameL >= oidLen */
++ oid vn_ge_oid[] = { 5, 'a', 'b' };
++ res = view_parse_oid(vn_ge_oid, sizeof(vn_ge_oid) / sizeof(vn_ge_oid[0]),
++ &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with viewNameLen >= oidLen rejected");
++
++ /* Character > 255 in viewName */
++ oid oob_char_vn[] = { 1, 300, 1, 3, 6, 1 };
++ res = view_parse_oid(oob_char_vn, sizeof(oob_char_vn) / sizeof(oob_char_vn[0]),
++ &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res != 0, "view_parse_oid with viewName char > 255 rejected");
++
++ /* Valid view entry OID parsing */
++ oid valid_view_oid[] = { 5, 'v', 'i', 'e', 'w', '1', 1, 3, 6, 1 };
++ viewName = NULL;
++ subtree = NULL;
++ res = view_parse_oid(valid_view_oid,
++ sizeof(valid_view_oid) / sizeof(valid_view_oid[0]),
++ &viewName, &viewNameLen, &subtree, &subtreeLen);
++ OK(res == 0, "view_parse_oid with valid OID succeeded");
++ OK(viewName != NULL && viewNameLen == 5 && strcmp((char *)viewName, "view1") == 0,
++ "view_parse_oid parsed viewName correctly");
++ OK(subtree != NULL && subtreeLen == 4 &&
++ subtree[0] == 1 && subtree[1] == 3 && subtree[2] == 6 && subtree[3] == 1,
++ "view_parse_oid parsed subtree correctly");
++ free(viewName);
++ free(subtree);
++}
++
++/* =========================================================================
++ * Test sec2group_parse_oid() (Related VACM OID parsing)
++ * ========================================================================= */
++{
++ unsigned char *name = NULL;
++ size_t nameLen = 0;
++ int model = 0;
++ int res;
++
++ /* Large name length exceeding oidLen */
++ oid large_s2g_oid[] = { 3, 0xFFFFFFFFUL };
++ res = sec2group_parse_oid(large_s2g_oid, sizeof(large_s2g_oid) / sizeof(large_s2g_oid[0]),
++ &model, &name, &nameLen);
++ OK(res != 0, "sec2group_parse_oid with large name length rejected");
++
++ /* Short oidLen / NULL checks */
++ res = sec2group_parse_oid(NULL, 10, &model, &name, &nameLen);
++ OK(res != 0, "sec2group_parse_oid with NULL oidIndex rejected");
++
++ res = sec2group_parse_oid(large_s2g_oid, 0, &model, &name, &nameLen);
++ OK(res != 0, "sec2group_parse_oid with oidLen=0 rejected");
++
++ res = sec2group_parse_oid(large_s2g_oid, 1, &model, &name, &nameLen);
++ OK(res != 0, "sec2group_parse_oid with oidLen=1 rejected");
++
++ /* Valid sec2group entry OID parsing */
++ oid valid_s2g_oid[] = { 3, 5, 'u', 's', 'e', 'r', '1' };
++ name = NULL;
++ res = sec2group_parse_oid(valid_s2g_oid,
++ sizeof(valid_s2g_oid) / sizeof(valid_s2g_oid[0]),
++ &model, &name, &nameLen);
++ OK(res == 0, "sec2group_parse_oid with valid OID succeeded");
++ OK(model == 3, "sec2group_parse_oid parsed model correctly");
++ OK(name != NULL && nameLen == 5 && strcmp((char *)name, "user1") == 0,
++ "sec2group_parse_oid parsed name correctly");
++ free(name);
++}
++
++#endif /* !NETSNMP_NO_WRITE_SUPPORT */
@@ -26,6 +26,8 @@ SRC_URI = "${SOURCEFORGE_MIRROR}/net-snmp/net-snmp-${PV}.tar.gz \
file://0011-ac_add_search_path.m4-keep-consistent-between-32bit-.patch \
file://0012-apps-Makefile.in-Link-libraries-explicitly.patch \
file://netsnmp-swinst-crash.patch \
+ file://CVE-2026-138295_1.patch \
+ file://CVE-2026-138295_2.patch \
"
SRC_URI[sha256sum] = "16707719f833184a4b72835dac359ae188123b06b5e42817c00790d7dc1384bf"