Skip to contentSkip to conversation

linux-user: preserve incoming order of environment variables in the target

PATCH Superseded Andreas Schwab 2 participants 2 messages Mar 29, 2023

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: preserve incoming order of environment variables in the target

Do not reverse the order of envionment variables in the target environ array relative to the incoming environ order. Some testsuites depend on a specific order, even though it is not defined by any standard.

---
 linux-user/main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/main.c +6 -1
index 4b18461969..d0ede3f990 100644
@@ -691,8 +691,13 @@ int main(int argc, char **argv, char **envp)
     envlist = envlist_create();
 
     /* add current environment into the list */
+    /* envlist_setenv adds to the front of the list; to preserve environ
+       order add from back to front */
     for (wrk = environ; *wrk != NULL; wrk++) {
-        (void) envlist_setenv(envlist, *wrk);
+        continue;
+    }
+    while (wrk != environ) {
+        (void) envlist_setenv(envlist, *--wrk);
     }
 
     /* Read the stack limit from the kernel.  If it's "unlimited",
Signature · 7 lines
2.40.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Andreas Schwab

Do not reverse the order of envionment variables in the target environ

"environment"

Quoted 15 lines

array relative to the incoming environ order. Some testsuites depend on a specific order, even though it is not defined by any standard.

---
  linux-user/main.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
linux-user/main.c +0 -0
index 4b18461969..d0ede3f990 100644
@@ -691,8 +691,13 @@ int main(int argc, char **argv, char **envp)
      envlist = envlist_create();
 

linux-user/main.c int main(int argc, char **argv, char **envp) · line 701

Quoted 10 lines
linux-user/main.c +6 -1
      /* add current environment into the list */
+    /* envlist_setenv adds to the front of the list; to preserve environ
+       order add from back to front */
      for (wrk = environ; *wrk != NULL; wrk++) {
-        (void) envlist_setenv(envlist, *wrk);
+        continue;
+    }
+    while (wrk != environ) {
+        (void) envlist_setenv(envlist, *--wrk);
      }

Preferably using a dumber form (easier to review IMHO):

        while (wrk != environ) {
           wrk--;
           (void) envlist_setenv(envlist, *wrk);
        }