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

Re: Bug when $USERNAME is cyryllic



On Sat, Sep 30, 2023 at 10:05 PM Максим Щербаков
<herobrine135111@xxxxxxxxx> 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.
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("");
     }
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);


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