Date: Sat, 14 Jan 2017 00:36:50 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r312099 - stable/11/contrib/bsnmp/gensnmpdef Message-ID: <201701140036.v0E0aomH056673@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Sat Jan 14 00:36:50 2017 New Revision: 312099 URL: https://svnweb.freebsd.org/changeset/base/312099 Log: MFC r311750,r311754,r311757: r311750: 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). Found with: gensnmpdef /usr/local/share/snmp/mibs/IPV6-TC.txt r311754: Use calloc instead of malloc + memset(.., 0, ..) r311757: Similar to r311750, check for the result from smiGetModule to avoid a segfault when dereferencing a NULL pointer later on. Choose to just check for the NULL pointer in the next for-loop for now to fix the issue with a minimal amount of code churn sys/queue.h use here would make more sense than using a static table Modified: stable/11/contrib/bsnmp/gensnmpdef/gensnmpdef.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/bsnmp/gensnmpdef/gensnmpdef.c ============================================================================== --- stable/11/contrib/bsnmp/gensnmpdef/gensnmpdef.c Sat Jan 14 00:36:48 2017 (r312098) +++ stable/11/contrib/bsnmp/gensnmpdef/gensnmpdef.c Sat Jan 14 00:36:50 2017 (r312099) @@ -126,9 +126,11 @@ open_node(const SmiNode *n, u_int level, 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"); @@ -397,12 +399,11 @@ static void save_typdef(char *name) { struct tdef *t; - t = malloc(sizeof(struct tdef)); + t = calloc(1, sizeof(struct tdef)); if (t == NULL) err(1, NULL); - memset(t, 0 , sizeof(struct tdef)); t->name = name; SLIST_INSERT_HEAD(&tdefs, t, link); } @@ -559,7 +560,11 @@ main(int argc, char *argv[]) level = 0; last = NULL; for (opt = 0; opt < argc; opt++) { + if (mods[opt] == NULL) /* smiGetModule failed above */ + continue; n = smiGetFirstNode(mods[opt], SMI_NODEKIND_ANY); + if (n == NULL) + continue; for (;;) { if (do_typedef == 0) { level = open_node(n, level, &last);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701140036.v0E0aomH056673>