zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: "Максим Щербаков" <herobrine135111@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: Bug when $USERNAME is cyryllic
Date: Sun, 1 Oct 2023 11:05:15 -0700	[thread overview]
Message-ID: <CAH+w=7ZQc41R2QiNDKiT4gf-WFqOgVEMU8Z3uMx=vrpBt9f0uA@mail.gmail.com> (raw)
In-Reply-To: <816a211e-3907-420e-9c1d-d6489f805d7f@Spark>

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

On Sat, Sep 30, 2023 at 10:05 PM Максим Щербаков
<herobrine135111@gmail.com> wrote:
>
> As we can see, $LOGNAME is fine, but $USERNAME and %n are bad.

Patch appended.

As mentioned in another thread, this presumes that it's harmless to
metafy something that's already metafied.  If that's not true then the
patch will fix USERNAME but break LOGNAME.

Aside:  If USE_GETPWUID is not defined and DISABLE_DYNAMIC_NSS is also
defined, then both USERNAME and LOGNAME will be empty.

> zcompile: can't write zwc file: /home/Студент/.zc/.zcompdump-5.9.zwc

The opposite problem.

[-- Attachment #2: meta-username.txt --]
[-- Type: text/plain, Size: 1309 bytes --]

diff --git a/Src/init.c b/Src/init.c
index ffb017e22..799ad19f6 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1212,8 +1212,8 @@ setupvals(char *cmd, char *runscript, char *zsh_name)
 #ifdef USE_GETPWUID
     if ((pswd = getpwuid(cached_uid))) {
 	if (EMULATION(EMULATE_ZSH))
-	    home = metafy(pswd->pw_dir, -1, META_DUP);
-	cached_username = ztrdup(pswd->pw_name);
+	    home = ztrdup_metafy(pswd->pw_dir);
+	cached_username = ztrdup_metafy(pswd->pw_name);
     }
     else
 #endif /* USE_GETPWUID */
diff --git a/Src/params.c b/Src/params.c
index 5841308d7..50e8627d1 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -4561,7 +4561,7 @@ usernamesetfn(UNUSED(Param pm), char *x)
 	    zwarn("failed to change user ID: %e", errno);
 	else {
 	    zsfree(cached_username);
-	    cached_username = ztrdup(pswd->pw_name);
+	    cached_username = ztrdup_metafy(pswd->pw_name);
 	    cached_uid = pswd->pw_uid;
 	}
     }
diff --git a/Src/utils.c b/Src/utils.c
index 7028c155f..790625379 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1069,7 +1069,7 @@ get_username(void)
 	cached_uid = current_uid;
 	zsfree(cached_username);
 	if ((pswd = getpwuid(current_uid)))
-	    cached_username = ztrdup(pswd->pw_name);
+	    cached_username = ztrdup_metafy(pswd->pw_name);
 	else
 	    cached_username = ztrdup("");
     }

[-- Attachment #3: unmeta-zcompile.txt --]
[-- Type: text/plain, Size: 1815 bytes --]

diff --git a/Src/parse.c b/Src/parse.c
index a07a6cc71..e76602524 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -3217,12 +3217,14 @@ bin_zcompile(char *nam, char **args, Options ops, UNUSED(int func))
 
     if (!args[1] && !(OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a'))) {
 	queue_signals();
-	ret = build_dump(nam, dyncat(*args, FD_EXT), args, OPT_ISSET(ops,'U'),
+	dump = unmetafy(dyncat(*args, FD_EXT), NULL);
+	ret = build_dump(nam, dump, args, OPT_ISSET(ops,'U'),
 			 map, flags);
 	unqueue_signals();
 	return ret;
     }
-    dump = (strsfx(FD_EXT, *args) ? *args : dyncat(*args, FD_EXT));
+    dump = (strsfx(FD_EXT, *args) ? ztrdup(*args) : dyncat(*args, FD_EXT));
+    unmetafy(dump, NULL);
 
     queue_signals();
     ret = ((OPT_ISSET(ops,'c') || OPT_ISSET(ops,'a')) ?
@@ -3400,6 +3402,7 @@ build_dump(char *nam, char *dump, char **files, int ali, int map, int flags)
 
     for (hlen = FD_PRELEN, tlen = 0; *files; files++) {
 	struct stat st;
+	char *fnam;
 
 	if (check_cond(*files, "k")) {
 	    flags = (flags & ~(FDHF_KSHLOAD | FDHF_ZSHLOAD)) | FDHF_KSHLOAD;
@@ -3408,7 +3411,8 @@ build_dump(char *nam, char *dump, char **files, int ali, int map, int flags)
 	    flags = (flags & ~(FDHF_KSHLOAD | FDHF_ZSHLOAD)) | FDHF_ZSHLOAD;
 	    continue;
 	}
-	if ((fd = open(*files, O_RDONLY)) < 0 ||
+	fnam = unmeta(*files);
+	if ((fd = open(fnam, O_RDONLY)) < 0 ||
 	    fstat(fd, &st) != 0 || !S_ISREG(st.st_mode) ||
 	    (flen = lseek(fd, 0, 2)) == -1) {
 	    if (fd >= 0)
@@ -3417,8 +3421,10 @@ build_dump(char *nam, char *dump, char **files, int ali, int map, int flags)
 	    zwarnnam(nam, "can't open file: %s", *files);
 	    noaliases = ona;
 	    unlink(dump);
+	    zsfree(fnam);
 	    return 1;
 	}
+	zsfree(fnam);
 	file = (char *) zalloc(flen + 1);
 	file[flen] = '\0';
 	lseek(fd, 0, 0);

  parent reply	other threads:[~2023-10-01 18:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-01  5:04 Максим Щербаков
2023-10-01  7:04 ` Ellenor Bjornsdottir
2023-10-01  7:17   ` Максим Щербаков
2023-10-01 18:05 ` Bart Schaefer [this message]
2023-10-01 18:54   ` Максим
2023-10-01 20:35     ` Bart Schaefer
2023-10-02  4:50       ` Максим
2023-10-02 10:28       ` Peter Stephenson

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='CAH+w=7ZQc41R2QiNDKiT4gf-WFqOgVEMU8Z3uMx=vrpBt9f0uA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=herobrine135111@gmail.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).