aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/kern_environment.c
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2019-09-12 14:34:46 +0000
committerKyle Evans <kevans@FreeBSD.org>2019-09-12 14:34:46 +0000
commit5163b1a75c756d65891611b59dd4302f53e5825b (patch)
tree021f9a50aecb048d190236fc90e4c64c1e580edf /sys/kern/kern_environment.c
parent436c46875d665f16b7b8e270fc21ab8a4dbffbbd (diff)
downloadsrc-5163b1a75c756d65891611b59dd4302f53e5825b.tar.gz
src-5163b1a75c756d65891611b59dd4302f53e5825b.zip
Follow up r352244: kenv: tighten up assertions
As I like to forget: static kenv var formatting is actually such that an empty environment would be double null bytes. We should make sure that a non-zero buffer has at least enough for this, though most of the current usage is with a 4k buffer.
Notes
Notes: svn path=/head/; revision=352245
Diffstat (limited to 'sys/kern/kern_environment.c')
-rw-r--r--sys/kern/kern_environment.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/sys/kern/kern_environment.c b/sys/kern/kern_environment.c
index f7be09b6eb72..7c36a24ff75c 100644
--- a/sys/kern/kern_environment.c
+++ b/sys/kern/kern_environment.c
@@ -250,7 +250,15 @@ init_static_kenv(char *buf, size_t len)
char *eval;
KASSERT(!dynamic_kenv, ("kenv: dynamic_kenv already initialized"));
- KASSERT(len == 0 || *buf == '\0',
+ /*
+ * Suitably sized means it must be able to hold at least one empty
+ * variable, otherwise things go belly up if a kern_getenv call is
+ * made without a prior call to kern_setenv as we have a malformed
+ * environment.
+ */
+ KASSERT(len == 0 || len >= 2,
+ ("kenv: static env must be initialized or suitably sized"));
+ KASSERT(len == 0 || (*buf == '\0' && *(buf + 1) == '\0'),
("kenv: sized buffer must be initially empty"));
/*