Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] Unicode variables can be exported and are exported metafied



On Thu, 18 Dec 2014 21:19:25 +0300
ZyX <kp-pav@xxxxxxxxx> wrote: 
> You see here that variable named `ус` can be exported (not sure
> whether it is a bug or not),

I *think* that's a "don't do that unless you actually need to..." but
feel free to present evidence otherwise.

> but its 0x83 byte which is the last byte of the first unicode
> codepoint that forms the variable name represented as UTF-8 is using
> zsh `Meta` escape in the `env` output (which clearly is a bug assuming
> the fact that unicode variable is exported is not).

Yes, indeed.

diff --git a/Src/params.c b/Src/params.c
index 79088d1..b87598a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -4357,7 +4357,18 @@ arrfixenv(char *s, char **t)
 int
 zputenv(char *str)
 {
+    char *ptr;
     DPUTS(!str, "Attempt to put null string into environment.");
+    /*
+     * The environment uses NULL-terminated strings, so just
+     * unmetafy and ignore the length.
+     */
+    for (ptr = str; *ptr && *ptr != Meta; ptr++)
+	;
+    if (*ptr == Meta) {
+	str = dupstring(str);
+	unmetafy(str, NULL);
+    }
 #ifdef USE_SET_UNSET_ENV
     /*
      * If we are using unsetenv() to remove values from the
@@ -4366,7 +4377,6 @@ zputenv(char *str)
      * Unfortunately this is a slightly different interface
      * from what zputenv() assumes.
      */
-    char *ptr;
     int ret;
 
     for (ptr = str; *ptr && *ptr != '='; ptr++)

pws



Messages sorted by: Reverse Date, Date, Thread, Author