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

PATCH: Avoid loading the main zsh binary as a module



Was fiddling around a bit due to the previous issue, and noticed that
module_path=($'\0'); zmodload flurg
succeeded. I looked at man dlopen and found that dlopen(NULL, ) returns a
handle to the main program binary which we probably don't want to do here.

---
 Src/module.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Src/module.c b/Src/module.c
index e78bd82..ddd0d90 100644
--- a/Src/module.c
+++ b/Src/module.c
@@ -1576,7 +1576,9 @@ try_load_module(char const *name)
 	if (l + (**pp ? strlen(*pp) : 1) > PATH_MAX)
 	    continue;
 	sprintf(buf, "%s/%s.%s", **pp ? *pp : ".", name, DL_EXT);
-	ret = dlopen(unmeta(buf), RTLD_LAZY | RTLD_GLOBAL);
+	unmetafy(buf, NULL);
+	if (*buf) /* dlopen(NULL) returns a handle to the main binary */
+	    ret = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
     }
 
     return ret;
-- 
2.2.0.GIT



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