PATCH: fix getfpfunc metafication

Mikael Magnusson <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel
Message-ID <[email protected]>
It wouldn't load functions if they or the directory they were in had a
metafied byte in the name, for example れ has a 0x82 byte.
---
 Src/exec.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/Src/exec.c b/Src/exec.c
index 2a622230aa..f5c5e8e077 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -6256,29 +6256,34 @@ runshfunc(Eprog prog, FuncWrap wrap, char *name)
 Eprog
 getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only)
 {
-    char **pp, buf[PATH_MAX+1];
+    char **pp, buf[PATH_MAX];
     off_t len;
     off_t rlen;
     char *d;
     Eprog r;
     int fd;
 
+    char *su = unmeta(s);
+    if (su != s) su = dupstring(su);
     pp = alt_path ? alt_path : fpath;
+    char *ppu = "";
     for (; *pp; pp++) {
 	if (**pp) {
-	    if (snprintf(buf, PATH_MAX, "%s/%s", *pp, s) >= PATH_MAX)
+	    ppu = unmeta(*pp);
+	    if (ppu != *pp) ppu = dupstring(ppu);
+	    if (snprintf(buf, PATH_MAX, "%s/%s", ppu, su) >= PATH_MAX)
 		continue;
-	} else if (strlen(s) >= PATH_MAX) {
+	} else if (strlen(su) >= PATH_MAX) {
 	    continue;
 	} else {
-	    strcpy(buf, s);
+	    strcpy(buf, su);
+	    ppu = "";
 	}
-	if ((r = try_dump_file(*pp, s, buf, ksh, test_only))) {
+	if ((r = try_dump_file(ppu, s, buf, ksh, test_only))) {
 	    if (fdir)
-		*fdir = *pp;
+		*fdir = ppu;
 	    return r;
 	}
-	unmetafy(buf, NULL);
 	if (!access(buf, R_OK) && (fd = open(buf, O_RDONLY | O_NOCTTY)) != -1) {
 	    struct stat st;
 	    if (!fstat(fd, &st) && S_ISREG(st.st_mode) &&
@@ -6286,7 +6291,7 @@ getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only)
 		if (test_only) {
 		    close(fd);
 		    if (fdir)
-			*fdir = *pp;
+			*fdir = ppu;
 		    return &dummy_eprog;
 		}
 		d = (char *) zalloc(len + 1);
@@ -6303,7 +6308,7 @@ getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only)
 		    scriptname = oldscriptname;
 
 		    if (fdir)
-			*fdir = *pp;
+			*fdir = ppu;
 
 		    zfree(d, len + 1);
 
-- 
2.38.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.