Module Name: src
Committed By: christos
Date: Thu Jun 20 17:12:37 UTC 2019
Modified Files:
src/sys/net/npf: npf_tableset.c
Log Message:
Add error checking for previous memory allocation failure.
To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/net/npf/npf_tableset.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/npf/npf_tableset.c
diff -u src/sys/net/npf/npf_tableset.c:1.31 src/sys/net/npf/npf_tableset.c:1.32
--- src/sys/net/npf/npf_tableset.c:1.31 Thu Jun 20 13:08:52 2019
+++ src/sys/net/npf/npf_tableset.c Thu Jun 20 13:12:37 2019
@@ -39,7 +39,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.31 2019/06/20 17:08:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_tableset.c,v 1.32 2019/06/20 17:12:37 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -495,7 +495,7 @@ table_cidr_check(int alen, const npf_add
return 0;
}
-static void
+static int
table_ifaddr_insert(npf_table_t *t, const int alen, npf_tblent_t *ent)
{
const unsigned aidx = NPF_ADDRLEN2IDX(alen);
@@ -514,6 +514,9 @@ table_ifaddr_insert(npf_table_t *t, cons
newsize = toalloc * sizeof(npf_tblent_t *);
elements = kmem_zalloc(newsize, KM_NOSLEEP);
+ if (elements == NULL) {
+ return ENOMEM;
+ }
for (unsigned i = 0; i < used; i++) {
elements[i] = old_elements[i];
}
@@ -527,6 +530,7 @@ table_ifaddr_insert(npf_table_t *t, cons
}
t->t_elements[aidx][used] = ent;
t->t_used[aidx]++;
+ return 0;
}
/*
@@ -590,7 +594,9 @@ npf_table_insert(npf_table_t *t, const i
error = EINVAL;
break;
case NPF_TABLE_IFADDR:
- table_ifaddr_insert(t, alen, ent);
+ if ((error = table_ifaddr_insert(t, alen, ent)) != 0) {
+ break;
+ }
LIST_INSERT_HEAD(&t->t_list, ent, te_listent);
t->t_nitems++;
break;