Author: kevans
Date: Thu Sep 12 14:34:46 2019
New Revision: 352245
URL: https://svnweb.freebsd.org/changeset/base/352245

Log:
  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.

Modified:
  head/sys/kern/kern_environment.c

Modified: head/sys/kern/kern_environment.c
==============================================================================
--- head/sys/kern/kern_environment.c    Thu Sep 12 13:51:43 2019        
(r352244)
+++ head/sys/kern/kern_environment.c    Thu Sep 12 14:34:46 2019        
(r352245)
@@ -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"));
 
        /*
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to