[njs] Tests: dropping all environment variables in a portable way.

Dmitry Volyntsev xeioex at nginx.com
Thu Apr 27 00:30:09 UTC 2023


details:   https://hg.nginx.org/njs/rev/9fbae1f025e2
branches:  
changeset: 2089:9fbae1f025e2
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Apr 26 17:27:48 2023 -0700
description:
Tests: dropping all environment variables in a portable way.

This fixes njs_unit_test crash on macOS.

The issue was introduced in 0.7.8.

diffstat:

 src/test/njs_unit_test.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (35 lines):

diff -r 0c95481158e4 -r 9fbae1f025e2 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Apr 19 00:20:37 2023 -0700
+++ b/src/test/njs_unit_test.c	Wed Apr 26 17:27:48 2023 -0700
@@ -25223,6 +25223,14 @@ static njs_test_suite_t  njs_suites[] =
 };
 
 
+static const char  *restricted_environ[] = {
+    "TZ=UTC",
+    "DUP=bar",
+    "dup=foo",
+    NULL,
+};
+
+
 int njs_cdecl
 main(int argc, char **argv)
 {
@@ -25239,14 +25247,10 @@ main(int argc, char **argv)
         return (ret == NJS_DONE) ? EXIT_SUCCESS: EXIT_FAILURE;
     }
 
-    environ = NULL;
-
-    (void) putenv((char *) "TZ=UTC");
+    environ = (char **) restricted_environ;
+
     tzset();
 
-    (void) putenv((char *) "DUP=bar");
-    (void) putenv((char *) "dup=foo");
-
     njs_mm_denormals(1);
 
     njs_memzero(&stat, sizeof(njs_stat_t));


More information about the nginx-devel mailing list