zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: [BUG] Unicode variables can be exported and are exported metafied
Date: Fri, 19 Dec 2014 21:21:25 +0000	[thread overview]
Message-ID: <20141219212125.1e1fea6b@ntlworld.com> (raw)
In-Reply-To: <20141219181652.GA3996@localhost.mi.fu-berlin.de>

On Fri, 19 Dec 2014 19:17:37 +0100
"Christoph (Stucki) von Stuckrad" <stucki@mi.fu-berlin.de> wrote:
> On Thu, 18 Dec 2014, Bart Schaefer wrote:
> 
> > Are we sure it's even "legal" to export Unicode variable names?
> > Internally we can kinda ignore POSIX as we choose, but the
> > environment crosses those boundaries.
> 
> Independend of being 'legal' to me it seems dangerous!

Well, this seems to be controversial.  But it's not clear how useful such
variables are anyway.

This backs off yesterday's mess and ignores environment variable names
with characters with the top bit set.  We'll see if anyone trips over it.

pws

diff --git a/Src/params.c b/Src/params.c
index 1c51afd..b8e0c42 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -641,9 +641,17 @@ split_env_string(char *env, char **name, char **value)
     if (!env || !name || !value)
 	return 0;
 
-    tenv = metafy(env, strlen(env), META_HEAPDUP);
-    for (str = tenv; *str && *str != '='; str++)
-	;
+    tenv = strcpy(zhalloc(strlen(env) + 1), env);
+    for (str = tenv; *str && *str != '='; str++) {
+	if (STOUC(*str) >= 128) {
+	    /*
+	     * We'll ignore environment variables with names not
+	     * from the portable character set since we don't
+	     * know of a good reason to accept them.
+	     */
+	    return 0;
+	}
+    }
     if (str != tenv && *str == '=') {
 	*str = '\0';
 	*name = tenv;
@@ -4357,18 +4365,7 @@ 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
@@ -4377,11 +4374,21 @@ zputenv(char *str)
      * Unfortunately this is a slightly different interface
      * from what zputenv() assumes.
      */
+    char *ptr;
     int ret;
 
-    for (ptr = str; *ptr && *ptr != '='; ptr++)
+    for (ptr = str; *ptr && STOUC(*ptr) < 128 && *ptr != '='; ptr++)
 	;
-    if (*ptr) {
+    if (STOUC(*ptr) >= 128) {
+	/*
+	 * Environment variables not in the portable character
+	 * set are non-standard and we don't really know of
+	 * a use for them.
+	 *
+	 * We'll disable until someone complains.
+	 */
+	return 1;
+    } else if (*ptr) {
 	*ptr = '\0';
 	ret = setenv(str, ptr+1, 1);
 	*ptr = '=';


  parent reply	other threads:[~2014-12-19 21:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18 18:19 ZyX
2014-12-18 19:29 ` Peter Stephenson
2014-12-18 19:47   ` Peter Stephenson
2014-12-18 19:58     ` Bart Schaefer
2014-12-18 20:09       ` Peter Stephenson
     [not found]       ` <54933513.6010501@case.edu>
2014-12-18 20:20         ` Fwd: " Bart Schaefer
2014-12-19  9:29       ` Christoph (Stucki) von Stuckrad
2014-12-19 18:17       ` Christoph (Stucki) von Stuckrad
2014-12-19 20:13         ` Павлов Николай Александрович
2014-12-19 21:21         ` Peter Stephenson [this message]
2014-12-19 22:44           ` ZyX
2014-12-20  0:13             ` Stephane Chazelas
2014-12-20  9:27               ` ZyX
2014-12-20 10:08                 ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141219212125.1e1fea6b@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).