summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2017-01-12 13:54:29 +0000
committerPeter Stephenson <pws@zsh.org>2017-01-12 13:54:29 +0000
commit33799ae2b00c09445e2e47720bc740ec434416e4 (patch)
tree5ad8280e25112174a72c7924d637fb9fd44db2b3
parentd3cf8816dce8f41bba2436045f38e9884ba04cc0 (diff)
downloadzsh-33799ae2b00c09445e2e47720bc740ec434416e4.tar.gz
zsh-33799ae2b00c09445e2e47720bc740ec434416e4.zip
40335: More care with autoload function path.
If doing "autoload -X", the path present might actually be location of file containing the function with the autoload -X. Add an explicit flag to say it's a directory for autoload.
-rw-r--r--ChangeLog4
-rw-r--r--Src/builtin.c11
-rw-r--r--Src/exec.c7
-rw-r--r--Src/zsh.h1
-rw-r--r--Test/C04funcdef.ztst10
5 files changed, 27 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 010135a55..e44814b0c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2017-01-12 Peter Stephenson <p.stephenson@samsung.com>
+ * 40335: Src/builtin.c, Src/exec.c, Src/zsh.h,
+ Test/C04funcdef.ztst: be more careful autoload filename is
+ directory, not source location.
+
* Jens Elkner: 40333: Src/watch.c: Fix the utmpx interface for
watch as otherwise it failed on some OSes.
diff --git a/Src/builtin.c b/Src/builtin.c
index b986dd89a..716ddd429 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2936,10 +2936,11 @@ check_autoload(Shfunc shf, char *name, Options ops, int func)
{
return eval_autoload(shf, name, ops, func);
}
- if (OPT_ISSET(ops,'r') || OPT_ISSET(ops,'R'))
+ if ((OPT_ISSET(ops,'r') || OPT_ISSET(ops,'R')) &&
+ (shf->node.flags & PM_UNDEFINED))
{
char *dir_path;
- if (shf->filename) {
+ if (shf->filename && (shf->node.flags & PM_LOADDIR)) {
char *spec_path[2];
spec_path[0] = shf->filename;
spec_path[1] = NULL;
@@ -2964,6 +2965,7 @@ check_autoload(Shfunc shf, char *name, Options ops, int func)
dir_path = xsymlink(dir_path, 1);
}
shf->filename = ztrdup(dir_path);
+ shf->node.flags |= PM_LOADDIR;
return 0;
}
if (OPT_ISSET(ops,'R')) {
@@ -3017,7 +3019,8 @@ add_autoload_function(Shfunc shf, char *funcname)
{
char *nam;
if (*funcname == '/' && funcname[1] &&
- (nam = strrchr(funcname, '/')) && nam[1]) {
+ (nam = strrchr(funcname, '/')) && nam[1] &&
+ (shf->node.flags & PM_UNDEFINED)) {
char *dir;
nam = strrchr(funcname, '/');
if (nam == funcname) {
@@ -3028,6 +3031,7 @@ add_autoload_function(Shfunc shf, char *funcname)
}
zsfree(shf->filename);
shf->filename = ztrdup(dir);
+ shf->node.flags |= PM_LOADDIR;
shfunctab->addnode(shfunctab, ztrdup(nam), shf);
} else {
shfunctab->addnode(shfunctab, ztrdup(funcname), shf);
@@ -3278,6 +3282,7 @@ bin_functions(char *name, char **argv, Options ops, int func)
if (*argv) {
zsfree(shf->filename);
shf->filename = ztrdup(*argv);
+ on |= PM_LOADDIR;
}
shf->node.flags = on;
ret = eval_autoload(shf, funcname, ops, func);
diff --git a/Src/exec.c b/Src/exec.c
index 7bec7ce48..68c455b18 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -5160,7 +5160,8 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
pushheap();
noaliases = (shf->node.flags & PM_UNALIASED);
- if (shf->filename && shf->filename[0] == '/')
+ if (shf->filename && shf->filename[0] == '/' &&
+ (shf->node.flags & PM_LOADDIR))
{
char *spec_path[2];
spec_path[0] = dupstring(shf->filename);
@@ -5203,7 +5204,7 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
shf->funcdef = prog;
else
shf->funcdef = dupeprog(prog, 0);
- shf->node.flags &= ~PM_UNDEFINED;
+ shf->node.flags &= ~(PM_UNDEFINED|PM_LOADDIR);
zsfree(shf->filename);
shf->filename = fname;
} else {
@@ -5227,7 +5228,7 @@ loadautofn(Shfunc shf, int fksh, int autol, int current_fpath)
shf->funcdef = stripkshdef(prog, shf->node.nam);
else
shf->funcdef = dupeprog(stripkshdef(prog, shf->node.nam), 0);
- shf->node.flags &= ~PM_UNDEFINED;
+ shf->node.flags &= ~(PM_UNDEFINED|PM_LOADDIR);
zsfree(shf->filename);
shf->filename = fname;
}
diff --git a/Src/zsh.h b/Src/zsh.h
index 67c5a3587..7d18333be 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1823,6 +1823,7 @@ struct tieddata {
/* Remaining flags do not correspond directly to command line arguments */
#define PM_DONTIMPORT_SUID (1<<19) /* do not import if running setuid */
+#define PM_LOADDIR (1<<19) /* (function) filename gives load directory */
#define PM_SINGLE (1<<20) /* special can only have a single instance */
#define PM_LOCAL (1<<21) /* this parameter will be made local */
#define PM_SPECIAL (1<<22) /* special builtin parameter */
diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst
index 1821b786e..7100280f3 100644
--- a/Test/C04funcdef.ztst
+++ b/Test/C04funcdef.ztst
@@ -419,6 +419,16 @@
0:autoload -dX with path
>I have been loaded by default path.
+ (
+ fpath=(.)
+ print 'loadthisfunc() { autoload -X }' >loadthisfunc_sourceme
+ print 'print Function was loaded correctly.' >loadthisfunc
+ source $PWD/loadthisfunc_sourceme
+ loadthisfunc
+ )
+0: autoload -X interaction with absolute filename used for source location
+>Function was loaded correctly.
+
%clean
rm -f file.in file.out