From: Martijn van Duren Subject: snmpd: allow arbitrary string length in mib.y To: tech@openbsd.org Date: Sun, 19 Oct 2025 17:22:37 +0200 Hello, Right now mib.y operates on text buffers of 16384 bytes. This is more than enough for the MIB files we have in base, and was based on "this supports enough MIB files that I'm happy with it for now" and I vaguely remember hitting some limits when doubling the value, but can't quite seem to recall where. However, this limit did mean we use quite large buffers inside the yacc parser, and still meant we had to drop a few MIB files that can be found inside librenms' database, because of extremely long DESCRIPTION sections. With this diff we can gain the following files from librenms' database in direct parsing: - /var/www/librenms/mibs/cisco/CISCO-TC - /var/www/librenms/mibs/cisco/CISCO-CLASS-BASED-QOS-MIB We lose the following file because I moved the length checking into yylex, which means that that identifiers and typereferences are now checked early, and some variables from before fell through the cracks. This includes enum labels (see RFC2578 section 7.1.1): - /var/www/librenms/mibs/fortinet/MERU-TC Then there's a couple of files who changed motivation, in which I'm not too interested right now: - /var/www/librenms/mibs/huawei/HUAWEI-ENTITY-TRAP-MIB - /var/www/librenms/mibs/huawei/HUAWEI-TC-MIB - /var/www/librenms/mibs/hp/BLADETYPE2-SWITCH-MIB (now can't be parsed instead of missing symbols) - /var/www/librenms/mibs/cisco/CISCO-SWITCH-ENGINE-MIB (incorrect symbol import) - /var/www/librenms/mibs/adva/CM-FACILITY-MIB (IPV6-TC still doesn't parse) - /var/www/librenms/mibs/comware/HH3C-QOS-CAPABILITY-MIB (HH3C-OID-MIB still doesn't parse) - /var/www/librenms/mibs/nokia/TIMETRA-OAM-TEST-MIB (IEEE8021-CFM-MIB still doesn't resolve) - /var/www/librenms/mibs/nokia/1830/TN-OAM-TEST-MIB (IEEE8021-CFM-MIB still doesn't resolve) With this we gain the following MIBs because they can now resolve all their symbols: - CISCO-VTP-MIB - CISCO-PRIVATE-VLAN-MIB - CISCO-AUTH-FRAMEWORK-MIB - CISCO-CONFIG-MAN-MIB - CISCO-SLB-MIB - CISCO-ENHANCED-SLB-MIB - CISCO-ENTITY-DIAG-MIB - CISCO-ENTITY-EXT-MIB - CISCO-ENTITY-SENSOR-MIB - CISCO-ERR-DISABLE-MIB - CISCO-IF-EXTENSION-MIB - CISCO-IGMP-SNOOPING-MIB - CISCO-MEDIA-GATEWAY-MIB - CISCO-IPSEC-FLOW-MONITOR-MIB - CISCO-LWAPP-WLAN-MIB - CISCO-LWAPP-AP-MIB - CISCO-LWAPP-RF-MIB - CISCO-MAC-NOTIFICATION-MIB - CISCO-PAGP-MIB - CISCO-POWER-ETHERNET-EXT-MIB - CISCO-PROCESS-MIB - CISCO-SLB-EXT-MIB - CISCO-SLB-HEALTH-MON-MIB - CISCO-SNAPSHOT-MIB - CISCO-STACKWISE-MIB - CISCO-STP-EXTENSIONS-MIB - CISCO-VLAN-IFTABLE-RELATIONSHIP-MIB - CISCO-VLAN-MEMBERSHIP-MIB - CISCO-WAN-OPTIMIZATION-MIB While here also satisfy the includes when building with bison. OK? martijn@ diff f5e5829750f6127f5a1dc9c2407b424587303b2a 5b410676d7b6ff40dae953e6a4c1abd8a0ac1c12 commit - f5e5829750f6127f5a1dc9c2407b424587303b2a commit + 5b410676d7b6ff40dae953e6a4c1abd8a0ac1c12 blob - ae33b64280fbcd9766287f60f2908d08fcfbf7f0 blob + de66c9e27c9bd33f317d0dd75f049004be12ed38 --- usr.sbin/snmpd/mib.y +++ usr.sbin/snmpd/mib.y @@ -19,8 +19,10 @@ %{ #include +#include #include +#include #include #include #include @@ -30,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -44,12 +48,18 @@ #define MODULENAME_MAX 64 #define SYMBOLS_MAX 256 #define IMPORTS_MAX 16 -#define TEXT_MAX 16384 #ifndef nitems #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif +struct text { + char string[DESCRIPTOR_MAX + 1]; + char file[PATH_MAX]; + off_t start; + off_t end; +}; + struct objidcomponent { enum { OCT_DESCRIPTOR, @@ -202,29 +212,38 @@ int mib_item_oid(struct item *, int mib_macro(const char *); int mib_applicationsyntax(const char *); struct item *mib_oid(const char *, const struct oid_unresolved *); -int mib_moduleidentity(const char *, time_t, const char *, - const char *, const char *, const struct oid_unresolved *); -int mib_objectidentity(const char *, enum status, const char *, - const char *, const struct oid_unresolved *); -int mib_objecttype(const char *, void *, const char *, - enum access, enum status, const char *, const char *, - void *, void *, const struct oid_unresolved *); +int mib_moduleidentity(const char *, time_t, const struct text *, + const struct text *, const struct text *, + const struct oid_unresolved *); +int mib_objectidentity(const char *, enum status, + const struct text *, const struct text *, + const struct oid_unresolved *); +int mib_objecttype(const char *, void *, const struct text *, + enum access, enum status, const struct text *, + const struct text *, void *, void *, + const struct oid_unresolved *); int mib_notificationtype(const char *, void *, enum status, - const char *, const char *, const struct oid_unresolved *); -int mib_textualconvetion(const char *, const char *, enum status, - const char *, const char *, void *); + const struct text *, const struct text *, + const struct oid_unresolved *); +int mib_textualconvetion(const char *, const struct text *, + enum status, const struct text *, const struct text *, + void *); int mib_objectgroup(const char *, void *, enum status, - const char *, const char *, const struct oid_unresolved *); + const struct text *, const struct text *, + const struct oid_unresolved *); int mib_notificationgroup(const char *, void *, enum status, - const char *, const char *, const struct oid_unresolved *); -int mib_modulecompliance(const char *, enum status, const char *, - const char *, void *, const struct oid_unresolved *); + const struct text *, const struct text *, + const struct oid_unresolved *); +int mib_modulecompliance(const char *, enum status, + const struct text *, const struct text *, void *, + const struct oid_unresolved *); struct item *mib_item_find(struct item *, const char *); struct item *mib_item_parent(struct ber_oid *); -int mib_resolve_oid(struct oid_resolved *, +int mib_resolve_oid(struct oid_resolved *, struct oid_unresolved *, struct item *); int mib_resolve_item(struct item *); int mib_resolve_module(struct module *); +char *text_get(struct text *, int *); int module_cmp_cs(struct module *, struct module *); int module_cmp_ci(struct module *, struct module *); int item_cmp_cs(struct item *, struct item *); @@ -266,7 +285,7 @@ struct file { } file; typedef union { - char string[TEXT_MAX]; + struct text text; unsigned long long number; long long signednumber; char symbollist[SYMBOLS_MAX][DESCRIPTOR_MAX + 1]; @@ -280,7 +299,6 @@ typedef union { %} %token ERROR -%token HSTRING BSTRING /* RFC2578 section 3.7 */ %token ABSENT ACCESS AGENTCAPABILITIES ANY APPLICATION AUGMENTS BEGIN @@ -305,16 +323,16 @@ typedef union { /* X.208 */ %token PRODUCTION RANGESEPARATOR -%token typereference identifier TEXT HSTRING BSTRING +%token typereference identifier TEXT HSTRING BSTRING %token NUMBER %token SIGNEDNUMBER -%type moduleidentifier smiv2moduleidentifier +%type moduleidentifier smiv2moduleidentifier %type symbolsfrom %type symbollist -%type descriptor symbol +%type descriptor symbol %type objidcomponentfirst objidcomponent %type objidcomponentlist objectidentifiervalue -%type displaypart referpart unitspart +%type displaypart referpart unitspart %type