Commit 22d9227b4fb for php
commit 22d9227b4fb1609f9a4b6967a9c72da9e7ead8f2
Author: lazerg <lazerg2@gmail.com>
Date: Sat Nov 28 06:58:00 2026 +0500
ext/snmp: snmp_init_mib() crashes when $mibdirs is omitted or null
snmp_init_mib() passed ZSTR_VAL(mibdirs) to netsnmp_ds_set_string() even
when $mibdirs was null, so calling it without an argument or with null
crashed. It now passes NULL in that case, which makes net-snmp fall back
to its default MIB directories, as the RFC describes and as RSHUTDOWN
already does. The stub also lacked the = null default even though ZPP
treats the argument as optional, so debug builds hit an arginfo/zpp
mismatch on snmp_init_mib().
Fix GH-25858
Close GH-25861
diff --git a/NEWS b/NEWS
index 2613e6928c9..d14f4ba2d71 100644
--- a/NEWS
+++ b/NEWS
@@ -266,6 +266,10 @@ PHP NEWS
throws an Error instead of returning an object with unresolved values.
(Ilia Alshanetsky)
+- SNMP:
+ . Fixed bug GH-25858 (snmp_init_mib() crashes when $mibdirs is omitted or
+ null). (lazerg)
+
- SOAP:
. Fixed bug GH-25267 (NULL dereference in to_xml_any() with integer key).
(lazerg)
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 2504d79c004..2fb68368ef7 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -1853,7 +1853,7 @@ PHP_FUNCTION(snmp_init_mib)
}
shutdown_mib();
- netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, ZSTR_VAL(mibdirs));
+ netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, mibdirs ? ZSTR_VAL(mibdirs) : NULL);
#ifdef HAVE_NETSNMP_INIT_MIB
netsnmp_init_mib();
#else
diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php
index 48199f2a662..689884a94f4 100644
--- a/ext/snmp/snmp.stub.php
+++ b/ext/snmp/snmp.stub.php
@@ -192,7 +192,7 @@ function snmp_get_valueretrieval(): int {}
function snmp_read_mib(string $filename): bool {}
- function snmp_init_mib(?string $mibdirs): void {}
+ function snmp_init_mib(?string $mibdirs = null): void {}
/** @not-serializable */
class SNMP
diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h
index 5e8af709928..8b642f921c2 100644
Binary files a/ext/snmp/snmp_arginfo.h and b/ext/snmp/snmp_arginfo.h differ
diff --git a/ext/snmp/snmp_decl.h b/ext/snmp/snmp_decl.h
index f0b7f49d5a3..307485b784a 100644
Binary files a/ext/snmp/snmp_decl.h and b/ext/snmp/snmp_decl.h differ
diff --git a/ext/snmp/tests/gh25858.phpt b/ext/snmp/tests/gh25858.phpt
new file mode 100644
index 00000000000..305b67242fc
--- /dev/null
+++ b/ext/snmp/tests/gh25858.phpt
@@ -0,0 +1,14 @@
+--TEST--
+GH-25858 (snmp_init_mib() dereferences NULL when $mibdirs is omitted or null)
+--CREDITS--
+OmenP007
+--EXTENSIONS--
+snmp
+--FILE--
+<?php
+snmp_init_mib();
+snmp_init_mib(null);
+echo "Done\n";
+?>
+--EXPECT--
+Done