summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-04-21 18:04:11 +0100
committerPeter Stephenson <pws@zsh.org>2017-04-21 18:07:42 +0100
commita2e2f5668deeca554a429b6557a169ed25808f1c (patch)
treeba22c9d9c748cc9fcbf4859cd759af5d11db2aad
parent6cc6942cf5df0bff0a39da2e1707c82ad0987f66 (diff)
downloadzsh-a2e2f5668deeca554a429b6557a169ed25808f1c.tar.gz
zsh-a2e2f5668deeca554a429b6557a169ed25808f1c.zip
40990: Fix crash with bogus path in sh emaulation.
When startying in sh emulation don't link PATH-style parameters to array equivalents. To allow this to function, don't check for the linkage when exporting the colon-separated parameter.
-rw-r--r--ChangeLog6
-rw-r--r--Src/params.c51
2 files changed, 43 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index 4595c56d1..6566d23e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-21 Peter Stephenson <p.stephenson@samsung.com>
+
+ * 40990: Src/params.c: When starting in sh emulation, don't
+ link PATH-style parameters to array equivalents. Don't
+ check linkage when exporting colon-separated parameter.
+
2017-04-18 Daniel Shahaf <d.s@daniel.shahaf.name>
* 40973: Completion/Unix/Type/_remote_files: Fix completion of
diff --git a/Src/params.c b/Src/params.c
index a9683a6f6..d92dd228a 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -361,6 +361,17 @@ IPDEF7("PS3", &prompt3),
IPDEF7R("PS4", &prompt4),
IPDEF7("SPROMPT", &sprompt),
+#define IPDEF9F(A,B,C,D) {{NULL,A,D|PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT},BR((void *)B),GSU(vararray_gsu),0,0,NULL,C,NULL,0}
+#define IPDEF9(A,B,C) IPDEF9F(A,B,C,0)
+IPDEF9F("*", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
+IPDEF9F("@", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
+
+/*
+ * This empty row indicates the end of parameters available in
+ * all emulations.
+ */
+{{NULL,NULL,0},BR(NULL),NULL_GSU,0,0,NULL,NULL,NULL,0},
+
#define IPDEF8(A,B,C,D) {{NULL,A,D|PM_SCALAR|PM_SPECIAL},BR((void *)B),GSU(colonarr_gsu),0,0,NULL,C,NULL,0}
IPDEF8("CDPATH", &cdpath, "cdpath", 0),
IPDEF8("FIGNORE", &fignore, "fignore", 0),
@@ -374,17 +385,6 @@ IPDEF8("ZSH_EVAL_CONTEXT", &zsh_eval_context, "zsh_eval_context", PM_READONLY),
/* MODULE_PATH is not imported for security reasons */
IPDEF8("MODULE_PATH", &module_path, "module_path", PM_DONTIMPORT|PM_RESTRICTED),
-#define IPDEF9F(A,B,C,D) {{NULL,A,D|PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT},BR((void *)B),GSU(vararray_gsu),0,0,NULL,C,NULL,0}
-#define IPDEF9(A,B,C) IPDEF9F(A,B,C,0)
-IPDEF9F("*", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
-IPDEF9F("@", &pparams, NULL, PM_ARRAY|PM_SPECIAL|PM_DONTIMPORT|PM_READONLY),
-
-/*
- * This empty row indicates the end of parameters available in
- * all emulations.
- */
-{{NULL,NULL,0},BR(NULL),NULL_GSU,0,0,NULL,NULL,NULL,0},
-
#define IPDEF10(A,B) {{NULL,A,PM_ARRAY|PM_SPECIAL},BR(NULL),GSU(B),10,0,NULL,NULL,NULL,0}
/*
@@ -424,6 +424,26 @@ IPDEF10("pipestatus", pipestatus_gsu),
};
/*
+ * Alternative versions of colon-separated path parameters for
+ * sh emulation. These don't link to the array versions.
+ */
+static initparam special_params_sh[] = {
+IPDEF8("CDPATH", &cdpath, NULL, 0),
+IPDEF8("FIGNORE", &fignore, NULL, 0),
+IPDEF8("FPATH", &fpath, NULL, 0),
+IPDEF8("MAILPATH", &mailpath, NULL, 0),
+IPDEF8("WATCH", &watch, NULL, 0),
+IPDEF8("PATH", &path, NULL, PM_RESTRICTED),
+IPDEF8("PSVAR", &psvar, NULL, 0),
+IPDEF8("ZSH_EVAL_CONTEXT", &zsh_eval_context, NULL, PM_READONLY),
+
+/* MODULE_PATH is not imported for security reasons */
+IPDEF8("MODULE_PATH", &module_path, NULL, PM_DONTIMPORT|PM_RESTRICTED),
+
+{{NULL,NULL,0},BR(NULL),NULL_GSU,0,0,NULL,NULL,NULL,0},
+};
+
+/*
* Special way of referring to the positional parameters. Unlike $*
* and $@, this is not readonly. This parameter is not directly
* visible in user space.
@@ -753,9 +773,13 @@ createparamtable(void)
/* Add the special parameters to the hash table */
for (ip = special_params; ip->node.nam; ip++)
paramtab->addnode(paramtab, ztrdup(ip->node.nam), ip);
- if (!EMULATION(EMULATE_SH|EMULATE_KSH))
+ if (EMULATION(EMULATE_SH|EMULATE_KSH)) {
+ for (ip = special_params_sh; ip->node.nam; ip++)
+ paramtab->addnode(paramtab, ztrdup(ip->node.nam), ip);
+ } else {
while ((++ip)->node.nam)
paramtab->addnode(paramtab, ztrdup(ip->node.nam), ip);
+ }
argvparam = (Param) &argvparam_pm;
@@ -3857,8 +3881,7 @@ colonarrsetfn(Param pm, char *x)
*dptr = colonsplit(x, pm->node.flags & PM_UNIQUE);
else
*dptr = mkarray(NULL);
- if (pm->ename)
- arrfixenv(pm->node.nam, *dptr);
+ arrfixenv(pm->node.nam, *dptr);
zsfree(x);
}