Paul Otto
2018-01-26 08:34:52 UTC
This patch restores, and improves upon, expected behavior to BASH
compatibility which was lost beginning with 1.27.0. This was pulled into
Alpine 3.7 which, in turn was pulled into official Docker images beginning
with docker:17.12. As a result, a large number of CICD builds that use
"source filename" have broken everywhere.
According to the BASH documentation, the source command should:
Read and execute commands from filename in the current shell
environment and return the exit status of the last command executed from
filename. If filename does not contain a slash, filenames in PATH are
used to find the directory containing filename. The file searched for in
PATH need not be executable. When bash is not in posix mode,
the current directory is searched if no file is found in PATH.
This patch specifically checks for when commandname is "source", and only
performs the additional PWD search in that case, and only after it has
neither 1) short-circuited from a /; and 2) not been found somewhere within
the PATH.
shell/ash.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git i/shell/ash.c w/shell/ash.c
index 865159d20..6de68bc4d 100644
--- i/shell/ash.c
+++ w/shell/ash.c
@@ -12967,7 +12967,10 @@ find_dot_file(char *name)
if (strchr(name, '/'))
return name;
- while ((fullname = path_advance(&path, name)) != NULL) {
+ while ((fullname = path_advance(&path, name)) != NULL) {
+#if BASH_SOURCE
+ try_cur_dir:
+#endif
if ((stat(fullname, &statb) == 0) &&
S_ISREG(statb.st_mode)) {
/*
* Don't bother freeing here, since it will
@@ -12980,7 +12983,14 @@ find_dot_file(char *name)
}
/* not found in the PATH */
- ash_msg_and_raise_error("%s: not found", name);
+#if BASH_SOURCE
+ if (strcmp(commandname, "source") == 0) {
+ fullname = name;
+ goto try_cur_dir;
+ }
+#endif
+ /* not found at all */
+ ash_msg_and_raise_error("%s: not found", name);
/* NOTREACHED */
}
compatibility which was lost beginning with 1.27.0. This was pulled into
Alpine 3.7 which, in turn was pulled into official Docker images beginning
with docker:17.12. As a result, a large number of CICD builds that use
"source filename" have broken everywhere.
According to the BASH documentation, the source command should:
Read and execute commands from filename in the current shell
environment and return the exit status of the last command executed from
filename. If filename does not contain a slash, filenames in PATH are
used to find the directory containing filename. The file searched for in
PATH need not be executable. When bash is not in posix mode,
the current directory is searched if no file is found in PATH.
This patch specifically checks for when commandname is "source", and only
performs the additional PWD search in that case, and only after it has
neither 1) short-circuited from a /; and 2) not been found somewhere within
the PATH.
shell/ash.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git i/shell/ash.c w/shell/ash.c
index 865159d20..6de68bc4d 100644
--- i/shell/ash.c
+++ w/shell/ash.c
@@ -12967,7 +12967,10 @@ find_dot_file(char *name)
if (strchr(name, '/'))
return name;
- while ((fullname = path_advance(&path, name)) != NULL) {
+ while ((fullname = path_advance(&path, name)) != NULL) {
+#if BASH_SOURCE
+ try_cur_dir:
+#endif
if ((stat(fullname, &statb) == 0) &&
S_ISREG(statb.st_mode)) {
/*
* Don't bother freeing here, since it will
@@ -12980,7 +12983,14 @@ find_dot_file(char *name)
}
/* not found in the PATH */
- ash_msg_and_raise_error("%s: not found", name);
+#if BASH_SOURCE
+ if (strcmp(commandname, "source") == 0) {
+ fullname = name;
+ goto try_cur_dir;
+ }
+#endif
+ /* not found at all */
+ ash_msg_and_raise_error("%s: not found", name);
/* NOTREACHED */
}