From 60acee2df5464200ed29162d4c15016e87f89bd8 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 27 Aug 2020 20:05:07 -0700 Subject: [PATCH] avoid panic crash due to bad environment variable values; closes pterodactyl/panel#2275 --- environment/settings.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/environment/settings.go b/environment/settings.go index 32b2547..04dc386 100644 --- a/environment/settings.go +++ b/environment/settings.go @@ -2,6 +2,7 @@ package environment import ( "fmt" + "github.com/apex/log" "math" "strconv" ) @@ -118,7 +119,13 @@ func (v Variables) Get(key string) string { return fmt.Sprintf("%f", val.(float64)) case bool: return strconv.FormatBool(val.(bool)) + case string: + return val.(string) } - return val.(string) + // TODO: I think we can add a check for val == nil and return an empty string for those + // and this warning should theoretically never happen? + log.Warn(fmt.Sprintf("failed to marshal environment variable \"%s\" of type %+v into string", key, val)) + + return "" }