From 75a07f8834c847cbdc3871173bd94b4955e2e572 Mon Sep 17 00:00:00 2001 From: Alliballibaba Date: Fri, 12 Dec 2025 14:03:28 +0100 Subject: [PATCH] cleanup. --- caddy/caddy_test.go | 6 ++++-- env.go | 5 ++--- frankenphp.c | 2 +- frankenphp_test.go | 5 ++++- testdata/env/test-env.php | 3 +-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/caddy/caddy_test.go b/caddy/caddy_test.go index 812db7e8..96ea7eb5 100644 --- a/caddy/caddy_test.go +++ b/caddy/caddy_test.go @@ -23,8 +23,10 @@ var testPort = "9080" func TestMain(m *testing.M) { // setup custom environment vars for TestOsEnv - os.Setenv("ENV1", "value1") - os.Setenv("ENV2", "value2") + if os.Setenv("ENV1", "value1") != nil || os.Setenv("ENV2", "value2") != nil { + fmt.Println("Failed to set environment variables for tests") + os.Exit(1) + } os.Exit(m.Run()) } diff --git a/env.go b/env.go index f7bcd0df..31963ebd 100644 --- a/env.go +++ b/env.go @@ -13,8 +13,7 @@ import ( //export go_init_os_env func go_init_os_env(mainThreadEnv *C.zend_array) { - env := os.Environ() - for _, envVar := range env { + for _, envVar := range os.Environ() { key, val, _ := strings.Cut(envVar, "=") zkey := C.frankenphp_init_persistent_string(toUnsafeChar(key), C.size_t(len(key))) zvalStr := C.frankenphp_init_persistent_string(toUnsafeChar(val), C.size_t(len(val))) @@ -31,7 +30,7 @@ func go_putenv(name *C.char, nameLen C.int, val *C.char, valLen C.int) C.bool { goName := C.GoStringN(name, nameLen) if val == nil { - // If no "=" is present in putenv(...), unset the environment variable + // If no "=" is present, unset the environment variable return C.bool(os.Unsetenv(goName) == nil) } diff --git a/frankenphp.c b/frankenphp.c index dc89ed7e..6a3fa360 100644 --- a/frankenphp.c +++ b/frankenphp.c @@ -1071,7 +1071,7 @@ int frankenphp_execute_script(char *file_name) { zend_destroy_file_handle(&file_handle); - /* Reset values added through putenv() */ + /* Reset values the sandboxed environment */ if (sandboxed_env != NULL) { zend_hash_release(sandboxed_env); sandboxed_env = NULL; diff --git a/frankenphp_test.go b/frankenphp_test.go index 154ebaab..07b9590b 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -148,7 +148,10 @@ func TestMain(m *testing.M) { } // setup custom environment var for TestWorkerHasOSEnvironmentVariableInSERVER - os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value") + if os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value") != nil { + fmt.Println("Failed to set environment variable for tests") + os.Exit(1) + } os.Exit(m.Run()) } diff --git a/testdata/env/test-env.php b/testdata/env/test-env.php index 85181e12..002a45df 100644 --- a/testdata/env/test-env.php +++ b/testdata/env/test-env.php @@ -58,8 +58,7 @@ return function() { // Inserting an invalid variable should fail (null byte in key) putenv("INVALID\x0_VAR=value"); - $value = getenv("INVALID\x0_VAR"); - if ($value) { + if (getenv("INVALID\x0_VAR")) { echo "Invalid value was inserted (unexpected).\n"; } else { echo "Invalid value was not inserted.\n";