Skip to content

ext/snmp: snmp_init_mib() dereferences NULL when $mibdirs is omitted or null #25858

Done

Description

@OmenP007

Description

In ext/snmp/snmp.c (lines 1848-1865 on master), snmp_init_mib(?string $mibdirs = null) accepts optional nullable $mibdirs (Z_PARAM_PATH_STR_OR_NULL(mibdirs)), checks if (mibdirs != NULL) at line 1858, and then unconditionally calls netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIBDIRS, ZSTR_VAL(mibdirs)) at line 1863. Calling snmp_init_mib() with no arguments or null evaluates ZSTR_VAL(NULL) (0x18) and segfaults.
Suggested fix: Guard netsnmp_ds_set_string(..., ZSTR_VAL(mibdirs)) with if (mibdirs != NULL).

The following code:

<?php
snmp_init_mib();

Resulted in this output:

Segmentation fault (NULL pointer dereference in ZSTR_VAL(mibdirs))

But I expected this output instead:

bool(true) / no crash

PHP Version

8.6.0

Operating System

Any

Activity

  1. added a commit that references this issue on Nov 28, 2026
    22d9227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions