Skip to contentSkip to conversation

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

PATCH In review Andreas Schwab 3 participants 6 messages Mar 29, 2023 – Jun 13, 2023

lore
Share & tools
lore
#0 lore raw

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

Do not reverse the order of environment 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.

---
 bsd-user/main.c   | 10 +++++++++-
 linux-user/main.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
bsd-user/main.c +9 -1
index 89f225dead..eff834e8d8 100644
@@ -298,8 +298,16 @@ int main(int argc, char **argv)
 
     envlist = envlist_create();
 
-    /* add current environment into the list */
+    /*
+     * 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++) {
+        continue;
+    }
+    while (wrk != environ) {
+        wrk--;
         (void) envlist_setenv(envlist, *wrk);
     }
 
linux-user/main.c +9 -1
index 4b18461969..f0173ceefa 100644
@@ -690,8 +690,16 @@ int main(int argc, char **argv, char **envp)
 
     envlist = envlist_create();
 
-    /* add current environment into the list */
+    /*
+     * 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++) {
+        continue;
+    }
+    while (wrk != environ) {
+        wrk--;
         (void) envlist_setenv(envlist, *wrk);
     }
 
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 v3 1/1
#1 lore raw
Quoted 9 lines · Andreas Schwab

Do not reverse the order of environment 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.

---
  bsd-user/main.c   | 10 +++++++++-
  linux-user/main.c | 10 +++++++++-
  2 files changed, 18 insertions(+), 2 deletions(-)
Reviewed-by on v3 1/1
#2 lore raw

Re: [PATCH v3] linux-user,bsd-user: preserve incoming order of environment variables in the target

In reply to Andreas Schwab
Quoted 10 lines · Andreas Schwab

Do not reverse the order of environment 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.

---
 bsd-user/main.c   | 10 +++++++++-
 linux-user/main.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
Quoted 53 lines
bsd-user/main.c +9 -1
index 89f225dead..eff834e8d8 100644
@@ -298,8 +298,16 @@ int main(int argc, char **argv)
 
     envlist = envlist_create();
 
-    /* add current environment into the list */
+    /*
+     * 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++) {
+        continue;
+    }
+    while (wrk != environ) {
+        wrk--;
         (void) envlist_setenv(envlist, *wrk);
     }
 
linux-user/main.c +9 -2
index 4b18461969..f0173ceefa 100644
@@ -690,8 +690,16 @@ int main(int argc, char **argv, char **envp)
 
     envlist = envlist_create();
 
-    /* add current environment into the list */
+    /*
+     * 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++) {
+        continue;
+    }
+    while (wrk != environ) {
+        wrk--;
         (void) envlist_setenv(envlist, *wrk);
     }
 
--

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."

#5 lore raw
In reply to Andreas Schwab
Quoted 9 lines · Andreas Schwab

Do not reverse the order of environment 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.

---
  bsd-user/main.c   | 10 +++++++++-
  linux-user/main.c | 10 +++++++++-
  2 files changed, 18 insertions(+), 2 deletions(-)

I'll take this patch in my next PR, thanks!