Check result from smiGetFirstNode and smiGetNodeByOID

This avoids a segfault with malformed or unanticipated files,
like IPV6-TC.txt (a file containing just TEXTUAL-CONVENTIONS).

MFC after:	5 days
Found with:	gensnmpdef /usr/local/share/snmp/mibs/IPV6-TC.txt
This commit is contained in:
Enji Cooper 2017-01-09 05:51:38 +00:00
parent c7af73f3fb
commit c5f8d75113

View File

@ -126,9 +126,11 @@ open_node(const SmiNode *n, u_int level, SmiNode **last)
while (level < n->oidlen - 1) {
if (level >= cut) {
n1 = smiGetNodeByOID(level + 1, n->oid);
if (n1 == NULL)
continue;
pindent(level);
printf("(%u", n->oid[level]);
n1 = smiGetNodeByOID(level + 1, n->oid);
printf(" ");
print_name(n1);
printf("\n");
@ -560,6 +562,8 @@ main(int argc, char *argv[])
last = NULL;
for (opt = 0; opt < argc; opt++) {
n = smiGetFirstNode(mods[opt], SMI_NODEKIND_ANY);
if (n == NULL)
continue;
for (;;) {
if (do_typedef == 0) {
level = open_node(n, level, &last);