summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/gensnmpdef/gensnmpdef.c
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-01-14 00:36:50 +0000
committerngie <ngie@FreeBSD.org>2017-01-14 00:36:50 +0000
commit6c6edd6df2593574df12313e29501bc6e1cb668a (patch)
treec68264314f1d37a75f241485c401ecd3f7ae97ff /contrib/bsnmp/gensnmpdef/gensnmpdef.c
parent202c7be0d1f7b6d6b14504724fb06f1a4d7f6a1a (diff)
downloadFreeBSD-src-6c6edd6df2593574df12313e29501bc6e1cb668a.zip
FreeBSD-src-6c6edd6df2593574df12313e29501bc6e1cb668a.tar.gz
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
Diffstat (limited to 'contrib/bsnmp/gensnmpdef/gensnmpdef.c')
-rw-r--r--contrib/bsnmp/gensnmpdef/gensnmpdef.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/contrib/bsnmp/gensnmpdef/gensnmpdef.c b/contrib/bsnmp/gensnmpdef/gensnmpdef.c
index 32c835d..b0bfdaf 100644
--- a/contrib/bsnmp/gensnmpdef/gensnmpdef.c
+++ b/contrib/bsnmp/gensnmpdef/gensnmpdef.c
@@ -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");
@@ -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);
OpenPOWER on IntegriCloud