aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst/config.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-19 02:39:23 +0900
committerOphestra <cat@gensokyo.uk>2025-10-19 02:39:49 +0900
commitd87020f0ca6897fbc1ba815fc1d9d048795e8749 (patch)
treed8743f9d80fd8457681f84c59974038479891b15 /hst/config.go
parente47aebb7a0de9b3b9f0345db68ff0119e6cc12c0 (diff)
hst/config: validate env early
This should happen in hst since it requires no system state. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'hst/config.go')
-rw-r--r--hst/config.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/hst/config.go b/hst/config.go
index 1b07755c..8a966059 100644
--- a/hst/config.go
+++ b/hst/config.go
@@ -3,6 +3,7 @@ package hst
import (
"errors"
"strconv"
+ "strings"
"hakurei.app/container/check"
)
@@ -45,6 +46,9 @@ var (
// ErrIdentityBounds is returned by [Config.Validate] for an out of bounds [Config.Identity] value.
ErrIdentityBounds = errors.New("identity out of bounds")
+
+ // ErrEnviron is returned by [Config.Validate] if an environment variable name contains '=' or NUL.
+ ErrEnviron = errors.New("invalid environment variable name")
)
// Validate checks [Config] and returns [AppError] if an invalid value is encountered.
@@ -83,6 +87,14 @@ func (config *Config) Validate() error {
return &AppError{Step: "validate configuration", Err: ErrConfigNull,
Msg: "container configuration missing path to initial program"}
}
+
+ for key := range config.Container.Env {
+ if strings.IndexByte(key, '=') != -1 || strings.IndexByte(key, 0) != -1 {
+ return &AppError{Step: "validate configuration", Err: ErrEnviron,
+ Msg: "invalid environment variable " + strconv.Quote(key)}
+ }
+ }
+
return nil
}