diff --git a/backport-Fix-handling-of-skipped-directories.patch b/backport-Fix-handling-of-skipped-directories.patch new file mode 100644 index 0000000000000000000000000000000000000000..e873f42fb9159b984c707fa0a0c7f5ff84a7835e --- /dev/null +++ b/backport-Fix-handling-of-skipped-directories.patch @@ -0,0 +1,120 @@ +From a1e1592ac7028659d09eb3fa6c8a2227cba9f2a9 Mon Sep 17 00:00:00 2001 +From: Kurtis Rader +Date: Wed, 8 Jan 2020 19:14:31 -0800 +Subject: [PATCH] Fix handling of skipped directories + +The bug in `path_opentype()` fixed by this commit may affect other +scenarios but we know it affects autoloaded functions. Hence the unit +test for that scenario. + +Fixes #1454 + +(cherry picked from commit 3bc58164494eecc180e2bad966d7753bfdd1e295) +--- + src/cmd/ksh93/sh/path.c | 16 +++++++++------- + src/cmd/ksh93/tests/autoload.sh | 15 +++++++++++++++ + src/cmd/ksh93/tests/data/skipped_dir | 15 +++++++++++++++ + src/cmd/ksh93/tests/meson.build | 1 + + 4 files changed, 40 insertions(+), 7 deletions(-) + create mode 100644 src/cmd/ksh93/tests/autoload.sh + create mode 100644 src/cmd/ksh93/tests/data/skipped_dir + +diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c +index 69382f9..b7869b3 100644 +--- a/src/cmd/ksh93/sh/path.c ++++ b/src/cmd/ksh93/sh/path.c +@@ -475,28 +475,30 @@ Pathcomp_t *path_get(Shell_t *shp, const char *name) { + // + static_fn int path_opentype(Shell_t *shp, const char *name, Pathcomp_t *pp, int fun) { + int fd = -1; +- struct stat statb; +- Pathcomp_t *oldpp; + + if (!pp && !shp->pathlist) path_init(shp); + if (!fun && strchr(name, '/') && sh_isoption(shp, SH_RESTRICTED)) { + errormsg(SH_DICT, ERROR_exit(1), e_restricted, name); + __builtin_unreachable(); + } ++ ++ // The structure of this loop is slightly odd. It's a consequence of how path_nextcomp() works. ++ Pathcomp_t *next_pp = pp; + do { +- pp = path_nextcomp(shp, oldpp = pp, name, 0); +- while (oldpp && (oldpp->flags & PATH_SKIP)) oldpp = oldpp->next; +- if (fun && (!oldpp || !(oldpp->flags & PATH_FPATH))) continue; ++ pp = next_pp; ++ next_pp = path_nextcomp(shp, pp, name, NULL); ++ if (pp && (pp->flags & PATH_SKIP)) continue; ++ if (fun && (!pp || !(pp->flags & PATH_FPATH))) continue; + fd = sh_open(path_relative(shp, stkptr(shp->stk, PATH_OFFSET)), O_RDONLY | O_CLOEXEC, 0); ++ struct stat statb; + if (fd >= 0 && (fstat(fd, &statb) < 0 || S_ISDIR(statb.st_mode))) { + errno = EISDIR; + sh_close(fd); + fd = -1; + } +- } while (fd < 0 && pp); ++ } while (fd < 0 && next_pp); + + assert(fd < 0 || sh_iovalidfd(shp, fd)); +- + if (fd >= 0 && (fd = sh_iomovefd(shp, fd)) > 0) { + (void)fcntl(fd, F_SETFD, FD_CLOEXEC); + shp->fdstatus[fd] |= IOCLEX; +diff --git a/src/cmd/ksh93/tests/autoload.sh b/src/cmd/ksh93/tests/autoload.sh +new file mode 100644 +index 0000000..6aaa206 +--- /dev/null ++++ b/src/cmd/ksh93/tests/autoload.sh +@@ -0,0 +1,15 @@ ++# Verify the behavior of autoloaded functions. ++ ++# ==================== ++# Verify that directories in the path search list which should be skipped (e.g., because they don't ++# exist) interacts correctly with autoloaded functions. ++# ++# See https://github.com/att/ast/issues/1454 ++expect=$"Func cd called with |$TEST_DIR/usr|\n$TEST_DIR/usr" ++actual=$($SHELL "$TEST_ROOT/data/skipped_dir") ++actual_status=$? ++expect_status=0 ++[[ $actual_status == $expect_status ]] || ++ log_error "autoload function skipped dir test wrong status" "$expect_status" "$actual_status" ++[[ $actual == $expect ]] || ++ log_error "autoload function skipped dir test wrong output" "$expect" "$actual" +diff --git a/src/cmd/ksh93/tests/data/skipped_dir b/src/cmd/ksh93/tests/data/skipped_dir +new file mode 100644 +index 0000000..b8eeddc +--- /dev/null ++++ b/src/cmd/ksh93/tests/data/skipped_dir +@@ -0,0 +1,15 @@ ++# See https://github.com/att/ast/issues/1454 ++ ++mkdir -p "$TEST_DIR/usr/bin" ++print '#!/bin/sh' >"$TEST_DIR/usr/bin/cd" ++print 'builtin cd "$@"' >>"$TEST_DIR/usr/bin/cd" ++prefix="$TEST_DIR/ksh.$$" ++ ++FPATH="$prefix/bad:$prefix/functions" ++mkdir -p "$prefix/functions" ++print 'function cd { echo "Func cd called with |$*|"; command cd "$@"; }' >"$prefix/functions/cd" ++typeset -fu cd ++ ++PATH="/arglebargle:$PATH:$TEST_DIR/usr/bin:$TEST_DIR/bin" ++cd "$TEST_DIR/usr" ++pwd +diff --git a/src/cmd/ksh93/tests/meson.build b/src/cmd/ksh93/tests/meson.build +index 6a07d7c..26f2d43 100644 +--- a/src/cmd/ksh93/tests/meson.build ++++ b/src/cmd/ksh93/tests/meson.build +@@ -48,6 +48,7 @@ all_tests = [ + ['arrays'], + ['arrays2'], + ['attributes'], ++ ['autoload'], + ['basic', 90], + ['bracket'], + ['builtins'], +-- +1.8.3.1 + diff --git a/ksh.spec b/ksh.spec index 88683bb9eb89df87c6f6aacd71c788778e8f1cb9..6ec9352c1e927a11c1332d129c2f92e16751e8b5 100644 --- a/ksh.spec +++ b/ksh.spec @@ -1,6 +1,6 @@ Name: ksh Version: 2020.0.0 -Release: 6 +Release: 7 Summary: The Original ATT Korn Shell License: EPL URL: http://www.kornshell.com/ @@ -11,6 +11,7 @@ Source2: kshrc.rhs Source3: dotkshrc Patch1: CVE-2019-14868.patch +Patch2: backport-Fix-handling-of-skipped-directories.patch Patch9000: openEuler-skip-some-test.patch @@ -89,6 +90,12 @@ done %config(noreplace) %{_sysconfdir}/binfmt.d/kshcomp.conf %changelog +* Mon Mar 14 2022 renhongxun - 1:2020.0.0-7 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:bugfix with github patches + * Thu Mar 10 2022 wangjiang - 1:2020.0.0-6 - Type:enhancement - ID:NA