svn commit: r312098 - stable/10/contrib/bsnmp/gensnmpdef
Ngie Cooper
ngie at FreeBSD.org
Sat Jan 14 00:36:49 UTC 2017
Author: ngie
Date: Sat Jan 14 00:36:48 2017
New Revision: 312098
URL: https://svnweb.freebsd.org/changeset/base/312098
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/10/contrib/bsnmp/gensnmpdef/gensnmpdef.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/contrib/bsnmp/gensnmpdef/gensnmpdef.c
==============================================================================
--- stable/10/contrib/bsnmp/gensnmpdef/gensnmpdef.c Sat Jan 14 00:33:07 2017 (r312097)
+++ stable/10/contrib/bsnmp/gensnmpdef/gensnmpdef.c Sat Jan 14 00:36:48 2017 (r312098)
@@ -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);
More information about the svn-src-stable
mailing list