import OL ksh-1.0.6-7.0.1.el9_6.1

This commit is contained in:
eabdullin 2025-06-25 08:03:36 +00:00
parent b4f0d08150
commit fff6f09f74
4 changed files with 388 additions and 2 deletions

View File

@ -0,0 +1,150 @@
From d381f5fd4f7fb068315fdf403d30f39452d59699 Mon Sep 17 00:00:00 2001
From: Martijn Dekker <martijn@inlv.org>
Date: Sun, 27 Oct 2024 01:34:38 +0000
Subject: [PATCH] Fix crash on 'exec' after 'unset SHLVL' (re: fa0f9796)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Vincent Mihalkovič (@vmihalko) reports:
> If the user unsets the SHLVL variable and later replaces the
> shell by executing a command, ksh will segfault.
>
> Reproducer
>
> # unset -v SHLVL
> # exec bash
> Segmaentation fault (core dumped)
>
> Reason
>
> The reason for this is that the SHLVL variable is getting
> decremented without any guard making sure it's still in the
> environment, see:
>
> src/cmd/ksh93/bltins/misc.c:
> 145: /* if the main shell is about to be replaced, decrease SHLVL
> to cancel out a subsequent increase */
> 146: if(!sh.realsubshell)
> 147: (*SHLVL->nvalue.ip)--;
This should be fixed so that SHLVL can be unset safely and lose its
special properties like other special variables do.
src/cmd/ksh93/sh/init.c,
src/cmd/ksh93/include/shell.h:
- Move the static 'shlvl' in init.c to the sh state struct, so that
'sh.shlvl' can be accessed from the entire ksh93 code base.
- Change its type from int to int32_t -- this is more correct as
nv_getval() uses this type to retrieve the value. In practice,
this makes no difference because sizeof(int) == sizeof(int32_t),
but this is not guaranteed by the standards.
src/cmd/ksh93/bltins/misc.c:
- Access sh.shlvl directly instead of dereferencing the SHLVL value
pointer, as this pointer is invalidated upon 'unset SHLVL'. This
fixes the bug.
Resolves: https://github.com/ksh93/ksh/issues/788
---
src/cmd/ksh93/bltins/misc.c | 2 +-
src/cmd/ksh93/include/shell.h | 1 +
src/cmd/ksh93/sh/init.c | 15 +++++++--------
src/cmd/ksh93/tests/variables.sh | 7 +++++++
4 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/cmd/ksh93/bltins/misc.c b/src/cmd/ksh93/bltins/misc.c
index 92b0183..808241f 100644
--- a/src/cmd/ksh93/bltins/misc.c
+++ b/src/cmd/ksh93/bltins/misc.c
@@ -147,7 +147,7 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
return 1;
/* if the main shell is about to be replaced, decrease SHLVL to cancel out a subsequent increase */
if(!sh.realsubshell)
- (*SHLVL->nvalue.ip)--;
+ sh.shlvl--;
/* force bad exec to terminate shell */
pp = (struct checkpt*)sh.jmplist;
pp->mode = SH_JMPEXIT;
diff --git a/src/cmd/ksh93/include/shell.h b/src/cmd/ksh93/include/shell.h
index 58e2f2a..0613ceb 100644
--- a/src/cmd/ksh93/include/shell.h
+++ b/src/cmd/ksh93/include/shell.h
@@ -270,6 +270,7 @@ struct Shell_s
* Programs using libshell should not rely on them as they may change. */
int subshell; /* set for virtual subshell */
int realsubshell; /* ${.sh.subshell}, actual subshell level (including virtual and forked) */
+ int32_t shlvl; /* $SHLVL, non-subshell child shell level */
char shcomp; /* set when running shcomp */
unsigned char trapnote; /* set when trap/signal is pending */
struct sh_scoped st; /* scoped information */
diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c
index 15c0736..f4daaac 100644
--- a/src/cmd/ksh93/sh/init.c
+++ b/src/cmd/ksh93/sh/init.c
@@ -224,7 +224,6 @@ static Init_t *nv_init(void);
#if SHOPT_STATS
static void stat_init(void);
#endif
-static int shlvl;
static int rand_shift;
/*
@@ -1354,8 +1353,8 @@ Shell_t *sh_init(int argc,char *argv[], Shinit_f userinit)
sfprintf(sh.strbuf,"%s/.kshrc",nv_getval(HOME));
nv_putval(ENVNOD,sfstruse(sh.strbuf),NV_RDONLY);
}
- *SHLVL->nvalue.ip +=1;
- nv_offattr(SHLVL,NV_IMPORT);
+ sh.shlvl++;
+ nv_offattr(SHLVL,NV_IMPORT);
#if SHOPT_SPAWN
{
/*
@@ -1668,13 +1667,13 @@ int sh_reinit(char *argv[])
memset(sh.st.trapcom,0,(sh.st.trapmax+1)*sizeof(char*));
sh_sigreset(0);
/* increase SHLVL */
- if(!(SHLVL->nvalue.ip))
+ if(!(SHLVL->nvalue.lp))
{
- shlvl = 0;
- SHLVL->nvalue.ip = &shlvl;
+ sh.shlvl = 0;
+ SHLVL->nvalue.lp = &sh.shlvl;
nv_onattr(SHLVL,NV_INTEGER|NV_EXPORT|NV_NOFREE);
}
- *SHLVL->nvalue.ip +=1;
+ sh.shlvl++;
nv_offattr(SHLVL,NV_IMPORT);
sh.st.filename = sh_strdup(sh.lastarg);
nv_delete(NULL, NULL, 0);
@@ -1823,7 +1822,7 @@ static Init_t *nv_init(void)
sh.nvfun.last = (char*)&sh;
sh.nvfun.nofree = 1;
sh.var_base = sh.var_tree = sh_inittree(shtab_variables);
- SHLVL->nvalue.ip = &shlvl;
+ SHLVL->nvalue.lp = &sh.shlvl;
ip->IFS_init.hdr.disc = &IFS_disc;
ip->PATH_init.disc = &RESTRICTED_disc;
ip->PATH_init.nofree = 1;
diff --git a/src/cmd/ksh93/tests/variables.sh b/src/cmd/ksh93/tests/variables.sh
index 7d2de08..08a0789 100755
--- a/src/cmd/ksh93/tests/variables.sh
+++ b/src/cmd/ksh93/tests/variables.sh
@@ -1609,5 +1609,12 @@ got=$(set +x; { "$SHELL" -c '
"(expected status 0, $(printf %q "$exp");" \
"got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"), $(printf %q "$got"))"
+# ======
+# exec after unset SHLVL
+# https://github.com/ksh93/ksh/issues/788
+{ "$SHELL" -c 'unset SHLVL; exec true'; } 2>/dev/null
+(((e=$?)==0)) || err_exit "crash after unsetting SHLVL" \
+ "(expected status 0, got status $e$( ((e>128)) && print -n /SIG && kill -l "$e"))"
+
# ======
exit $((Errors<125?Errors:125))
--
2.47.0

View File

@ -0,0 +1,118 @@
From 5def43983de3ecfa38c805c02a1f0d6f1581160c Mon Sep 17 00:00:00 2001
From: Martijn Dekker <martijn@inlv.org>
Date: Thu, 31 Oct 2024 20:56:54 +0000
Subject: [PATCH] Add forking workaround for block stdout redir (re: e373e8c1)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reproducer:
ok=$({ true >&2; } >&2; echo OK); echo $ok
This should output "OK" but currently outputs nothing.
Looks like the sh_subfork() workaround must also be implemented for
the TSETIO case in sh_exec(), as that is where redirections for
blocks and compound commands are handled. This avoids inconsistent
behaviour that happens if sh_subfork() is called later for the
inside redirection.
src/cmd/ksh93/sh/xec.c: sh_exec(): case TSETIO:
- Also fork if standard output redirections attached to blocks are
executed within a non-subshare command substitution.
Thanks to Vincent Mihalkovič (@vmihalko) for the report.
Resolves: https://github.com/ksh93/ksh/issues/784
---
NEWS | 8 ++++++++
src/cmd/ksh93/include/version.h | 2 +-
src/cmd/ksh93/sh/xec.c | 15 ++++++++-------
src/cmd/ksh93/tests/io.sh | 32 +++++++++++++++++++++++++++++++-
4 files changed, 48 insertions(+), 9 deletions(-)
diff --git a/src/cmd/ksh93/sh/xec.c b/src/cmd/ksh93/sh/xec.c
index 01b390d..ca67142 100644
--- a/src/cmd/ksh93/sh/xec.c
+++ b/src/cmd/ksh93/sh/xec.c
@@ -1682,21 +1682,22 @@ int sh_exec(const Shnode_t *t, int flags)
int jmpval, waitall = 0;
int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
struct checkpt *buffp = (struct checkpt*)stkalloc(sh.stk,sizeof(struct checkpt));
- if(sh.subshell && !sh.subshare && t->fork.forkio)
+ if(sh.subshell && !sh.subshare)
{
- /* Subshell forking workaround for https://github.com/ksh93/ksh/issues/161
- * Check each redirection for >&- or <&-
+ /* Subshell forking workaround for:
+ * https://github.com/ksh93/ksh/issues/161 (check each redirection for >&- or <&-)
+ * https://github.com/ksh93/ksh/issues/784 (check for stdout in a command substitution)
* TODO: find the elusive real fix */
- struct ionod *i = t->fork.forkio;
- do
+ struct ionod *i;
+ for (i = t->fork.forkio; i; i = i->ionxt)
{
- if((i->iofile & ~(IOUFD|IOPUT)) == (IOMOV|IORAW) && !strcmp(i->ioname,"-"))
- {
+ unsigned f = i->iofile;
+ if ((f & ~(IOUFD|IOPUT))==(IOMOV|IORAW) && !strcmp(i->ioname,"-") || (f & IOUFD)==1 && sh.comsub)
+ {
sh_subfork();
break;
}
}
- while(i = i->ionxt);
}
sh_pushcontext(buffp,SH_JMPIO);
if(type&FPIN)
diff --git a/src/cmd/ksh93/tests/io.sh b/src/cmd/ksh93/tests/io.sh
index 6f70dc1..861bf27 100755
--- a/src/cmd/ksh93/tests/io.sh
+++ b/src/cmd/ksh93/tests/io.sh
@@ -927,7 +927,6 @@ fi
# ======
# Command substitution hangs, writing infinite zero bytes, when redirecting standard output on a built-in that forks
# https://github.com/ksh93/ksh/issues/416
-exp='line'
"$SHELL" -c 'echo "$(ulimit -t unlimited >/dev/null 2>&1; echo "ok $$")"' >out 2>&1 &
pid=$!
(sleep 1; kill -9 "$pid") 2>/dev/null &
@@ -938,6 +937,37 @@ then kill "$!" # the sleep process
else err_exit "comsub hangs after fork with stdout redirection"
fi
+# https://github.com/ksh93/ksh/issues/416#issuecomment-1008866883
+exp='line'
+"$SHELL" -c 'alias foo=bar; echo $(alias foo >/dev/null; echo "$1")' "$0" "$exp" >out 2>&1 &
+pid=$!
+(sleep 1; kill -9 "$pid") 2>/dev/null &
+if wait "$pid" 2>/dev/null
+then kill "$!" # the sleep process
+ [[ $(<out) == "$exp" ]] || err_exit "comsub fails after stdout redirection" \
+ "(expected '$exp', got '$(<out)')"
+else err_exit "comsub hangs after stdout redirection"
+fi
+
+# same bug for compound/block commands: https://github.com/ksh93/ksh/issues/784
+exp=$'funA\nA'
+"$SHELL" -c '
+ BugFunction() {
+ { echo "funA" >&2; } >&2
+ echo A
+ }
+ Result=$(BugFunction)
+ echo $Result
+' >out 2>&1 &
+pid=$!
+(sleep 1; kill -9 "$pid") 2>/dev/null &
+if wait "$pid" 2>/dev/null
+then kill "$!" # the sleep process
+ [[ $(<out) == "$exp" ]] || err_exit "double redirection in command substitution" \
+ "(expected $(printf %q "$exp"), got $(printf %q "$(<out)"))"
+else err_exit "double redirection in command substitution causes shell hang"
+fi
+
# ======
# https://github.com/ksh93/ksh/issues/161
got=$(

View File

@ -0,0 +1,94 @@
From 96d73c08a2786806f3def1fda66641b81e0af988 Mon Sep 17 00:00:00 2001
From: SHIMIZU Akifumi <shimizu.akifumi@fujitsu.com>
Date: Mon, 7 Apr 2025 19:47:16 +0900
Subject: [PATCH] Fix long multibyte characters paste issue via ssh (#840)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When I paste long multibyte characters(over 80 byte) to ksh via
SSH, the characters are not displayed correctly. For example, the
following input demonstrates the issue. ja_JP.UTF-8 encoding is
used.
Expected command line display:
$ echo "長い文字列を入れるとkshで文字列が乱れる場合があるようです"
Actual command line display:
$ です"echo "長い文字列を入れるとkshで文字列が乱れる場合がある
...with the cursor over the 'e' in 'echo'.
This issue appears to be caused by the ed_read() function splitting
a multibyte character sequence when reading into an 80-byte buffer.
This leads to incorrect character interpretation and display.
Therefore, we edited the code to handle the case where the buffer
size is full in the middle of a multi-byte character.
src/cmd/ksh93/sh/edit.c:
- putstack():
- Before retrying to interpret a multibyte character in case of a
split due to end of buffer, restore the start position 'p'.
- Fix zeroing out errno = EILSEQ.
- ed_getchar(): Avoid a potential buffer overflow in 'readin';
allow for an extra multibyte character, not merely an extra byte.
Co-authored-by: Martijn Dekker <martijn@inlv.org>
---
src/cmd/ksh93/edit/edit.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c
index 0ac54ba..1dcef1b 100644
--- a/src/cmd/ksh93/edit/edit.c
+++ b/src/cmd/ksh93/edit/edit.c
@@ -15,6 +15,7 @@
* Johnothan King <johnothanking@protonmail.com> *
* Anuradha Weeraman <anuradha@debian.org> *
* K. Eugene Carlson <kvngncrlsn@gmail.com> *
+* SHIMIZU Akifumi <shimizu.akifumi@fujitsu.com> *
* *
***********************************************************************/
/*
@@ -861,6 +862,7 @@ static int putstack(Edit_t *ep,char string[], int nbyte, int type)
}
else
{
+ char *prevp = p;
again:
if((c=mbchar(p)) >=0)
{
@@ -868,19 +870,20 @@ static int putstack(Edit_t *ep,char string[], int nbyte, int type)
if(type)
c = -c;
}
-#ifdef EILSEQ
- else if(errno == EILSEQ)
- errno = 0;
-#endif
else if((endp-p) < mbmax())
{
+ if(errno == EILSEQ)
+ errno = 0;
if ((c=ed_read(ep,ep->e_fd,endp, 1,0)) == 1)
{
+ p = prevp;
*++endp = 0;
goto again;
}
return c;
}
+ else if(errno == EILSEQ)
+ errno = 0;
else
{
ed_ringbell();
@@ -930,7 +933,7 @@ static int putstack(Edit_t *ep,char string[], int nbyte, int type)
int ed_getchar(Edit_t *ep,int mode)
{
int n, c;
- char readin[LOOKAHEAD+1];
+ char *readin = fmtbuf(LOOKAHEAD + mbmax());
if(!ep->e_lookahead)
{
ed_flush(ep);

View File

@ -4,7 +4,7 @@ URL: http://www.kornshell.com/
License: EPL-1.0
Epoch: 3
Version: 1.0.6
Release: 4%{?dist}
Release: 7.0.1%{?dist}.1
Source0: https://github.com/ksh93/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz
Source1: kshcomp.conf
Source2: kshrc.rhs
@ -29,6 +29,15 @@ Patch4: ksh-1.0.7-segfault-strdup.patch
#upstream commit: https://github.com/ksh93/ksh/commit/428c0917f3043358c9b54cc137a5037d69b01ed4
Patch5: ksh-1.0.9-trap-return-status.patch
#upstream commit: https://github.com/ksh93/ksh/commit/caae9aa23e2851cadf55f858a8f38b9f0de74314
Patch6: ksh-1.0.11-SHLVL.patch
#upstream commit: https://github.com/ksh93/ksh/commit/5def43983de3ecfa38c805c02a1f0d6f1581160c
Patch7: ksh-1.0.11-redir.patch
# upstream commit: https://github.com/ksh93/ksh/commit/96d73c08a2786806f3def1fda66641b81e0af988
Patch8: ksh-1.0.11-ssh-multibyte-long-paste.patch
Conflicts: pdksh
Requires: coreutils, diffutils
BuildRequires: gcc
@ -59,7 +68,7 @@ for f in -Wno-unknown-pragmas -Wno-missing-braces -Wno-unused-result -Wno-return
do
$CC $f -E - </dev/null >/dev/null 2>&1 && XTRAFLAGS="$XTRAFLAGS $f"
done
export CCFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing $XTRAFLAGS"
export CCFLAGS="$RPM_OPT_FLAGS $RPM_LD_FLAGS -fno-strict-aliasing $XTRAFLAGS -DSHOPT_AUDIT -D_AST_no_spawnveg=1"
export LDFLAGS="$RPM_LD_FLAGS"
./bin/package make
@ -150,6 +159,21 @@ fi
%config(noreplace) %{_sysconfdir}/binfmt.d/kshcomp.conf
%changelog
* Tue Jun 24 2025 EL Errata <el-errata_ww@oracle.com> - 1.0.6-7.0.1.1
- Disable _AST_no_spawnveg for taskset workaround [Orabug: 26754277]
* Tue Apr 22 2025 Vincent Mihalkovic <vmihalko@redhat.com> - 3:1.0.6-7
- Fix long multibyte characters paste issue via ssh
Resolves: RHEL-87336
* Wed Jan 22 2025 Vincent Mihalkovic <vmihalko@redhat.com> - 3:1.0.6-6
- Add forking workaround for block stdout redir
Resolves: RHEL-55913
* Mon Jan 13 2025 Vincent Mihalkovic <vmihalko@redhat.com> - 3:1.0.6-5
- Fix crash on 'exec' after 'unset SHLVL'
Resolves: RHEL-59656
* Tue Oct 01 2024 Vincent Mihalkovic <vmihalko@redhat.com> - 3:1.0.6-4
- Fix bad default 'return' status in traps
Resolves: RHEL-62228