AT&T AST (att/ast) on github has rewound their repo back to ksh93u+. See

https://github.com/att/ast/issues/1464 and
https://github.com/att/ast/issues/1466.

The reason for the rewind back to 93u+ instead of 93v- was that it was an
abandoned unstable buggy unfinished beta. A full explanation of this can be
found here, https://github.com/att/ast/issues/1466#issuecomment-589942449.

The version number is reverted back to 93u and an EPOCH bump, though not
needed, documents this siesmic shift.
This commit is contained in:
Cy Schubert 2020-02-22 22:38:35 +00:00
parent e7af5367ff
commit 1b4fbb7092
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=526859
16 changed files with 319 additions and 131 deletions

View File

@ -1,17 +1,34 @@
# $FreeBSD$
# Make sure that your configuration DOES NOT set ANY gcc-related
# variables. ksh93 will not compile if you set even the seemingly
# most unrelated variable related to gcc configuration. This means
# especially any flag which attempts to set the cputype. Setting the
# cputype does absolutely nothing except cause systems to fail in
# horrible ways. For any modern processor, setting the cputype only
# serves to expose gcc bugs and does nothing to speed up any known
# program. If you are really unconvinced, go ahead but do not
# complain to me about it.
# Do not update this port to 93v. 93v was an abandoned beta when
# David Korn left the project. It was subsequently reverted to 93u.
# https://github.com/att/ast/issues/1466#issuecomment-589942449
PORTNAME= ksh93
DISTVERSION= 2020.0.1
DISTVERSION= 93u
PORTREVISION= 1
PORTEPOCH= 1
PORTEPOCH= 2
CATEGORIES= shells
DIST_SUBDIR= ksh93
MAINTAINER= cy@FreeBSD.org
COMMENT= AT&T KornShell 93
LICENSE= EPL
USES= compiler:c11 meson ninja python:build
BROKEN_aarch64= Fails to compile: needs sbrk
USES= compiler:c11
USE_GITHUB= yes
GH_ACCOUNT= att
@ -20,15 +37,18 @@ GH_PROJECT= ast
KSH_CONFLICTS= pdksh-*
KSH93_CONFLICTS= ksh93-devel-* ast-ksh-*
MESON_BUILD_DIR= build
OPTIONS_DEFAULT= KSH93
OPTIONS_DEFAULT= KSH93 EXAMPLES
OPTIONS_DEFINE= EXAMPLES STATIC
OPTIONS_SINGLE= BIN_KSH
OPTIONS_SINGLE_BIN_KSH= KSH KSH93
KSH_DESC= Install to ${PREFIX}/bin/ksh
KSH93_DESC= Install to ${PREFIX}/bin/ksh93
KSH93_EXTRA_PATCHES= ${FILESDIR}/extra-patch-install-as-ksh93
CFLAGS+= -DMAP_TYPE
LDFLAGS+= -lm
MAKE_ENV= CCFLAGS="-Wno-unused-value -Wno-parentheses -Wno-logical-op-parentheses" CFLAGS="${CFLAGS}"
STATIC_MAKE_ENV= LDFLAGS+=-static
KSH_PLIST_SUB= 93=""
KSH93_PLIST_SUB= 93="93"
@ -39,14 +59,25 @@ KSH93_PLIST_SUB= 93="93"
BROKEN= GCC 9.1 changes the output of `gcc -E` which breaks the conf.sh script, fixed in shells/ksh93-devel
.endif
post-patch:
@${REINPLACE_CMD} -e '/for name in/ s|python.*|${PYTHON_CMD}|g' ${WRKSRC}/scripts/python.sh
@${REINPLACE_CMD} -e 's|SF_FLAGS|SFIO_FLAGS|g' ${WRKSRC}/src/lib/libast/include/sfio*.h ${WRKSRC}/src/lib/libast/sfio/*.c
.if ${PORT_OPTIONS:MKSH93}
@${MV} ${WRKSRC}/src/cmd/ksh93/docs/ksh.1 ${WRKSRC}/src/cmd/ksh93/docs/ksh93.1
.endif
.if ${PORT_OPTIONS:MKSH}
@# Keep portlint happy
PNAME= ksh93
.else
PNAME= ksh
.endif
post-patch:
@${REINPLACE_CMD} -e 's|SF_FLAGS|SFIO_FLAGS|g' ${WRKSRC}/src/lib/libast/include/sfio*.h ${WRKSRC}/src/lib/libast/sfio/*.c
do-build:
@cd ${WRKSRC}/ && ${SETENV} -i ${MAKE_ENV} ${SH} bin/package flat make ksh93
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/bin/ksh ${STAGEDIR}${PREFIX}/bin/${PNAME}
${INSTALL_MAN} ${WRKSRC}/man/man1/sh.1 ${STAGEDIR}${MAN1PREFIX}/man/man1/${PNAME}.1
${MKDIR} ${STAGEDIR}${EXAMPLESDIR}/
cd ${WRKSRC}/fun/ && ${INSTALL_SCRIPT} dirs popd pushd ${STAGEDIR}${EXAMPLESDIR}/
do-test:
cd ${WRKSRC}/src/cmd/ksh93/tests/ && ${SETENV} SHELL=${WRKSRC}/bin/ksh ${WRKSRC}/bin/ksh shtests
.include <bsd.port.post.mk>

View File

@ -1,3 +1,3 @@
TIMESTAMP = 1578621862
SHA256 (att-ast-2020.0.1_GH0.tar.gz) = dc022c80021bbe27aabcdcd90cc5caeabff1955cf5fdfcc32ebd410b0da141be
SIZE (att-ast-2020.0.1_GH0.tar.gz) = 2023438
TIMESTAMP = 1582352303
SHA256 (ksh93/att-ast-93u_GH0.tar.gz) = 4cf10ae50306361a18d900008961093b5c2c51d69f4e50d14b911a8ce014d37f
SIZE (ksh93/att-ast-93u_GH0.tar.gz) = 12960931

View File

@ -1,25 +0,0 @@
--- ./src/cmd/ksh93/meson.build.orig 2019-08-25 15:52:12.000000000 -0700
+++ ./src/cmd/ksh93/meson.build 2019-08-28 12:34:47.804820000 -0700
@@ -26,19 +26,19 @@
dependencies: [libm_dep, libexecinfo_dep, libdl_dep, libsocket_dep, libnsl_dep],
install: get_option('default_library') == 'shared')
-ksh93_exe = executable('ksh', ['sh/pmain.c'], c_args: shared_c_args,
+ksh93_exe = executable('ksh93', ['sh/pmain.c'], c_args: shared_c_args,
include_directories: [configuration_incdir, ksh93_incdir],
link_with: [libksh, libast, libcmd, libdll],
dependencies: [libm_dep, libexecinfo_dep, libdl_dep],
install: true)
-shcomp_exe = executable('shcomp', ['sh/shcomp.c'], c_args: shared_c_args,
+shcomp_exe = executable('shcomp93', ['sh/shcomp.c'], c_args: shared_c_args,
include_directories: [configuration_incdir, ksh93_incdir],
link_with: [libksh, libast, libcmd, libdll],
dependencies: [libm_dep, libexecinfo_dep, libdl_dep, libsocket_dep, libnsl_dep],
install: true)
-install_man('docs/ksh.1')
+install_man('docs/ksh93.1')
test_dir = join_paths(meson.current_source_dir(), 'tests')
test_driver = join_paths(test_dir, 'util', 'run_test.sh')

View File

@ -1,78 +0,0 @@
diff --git a/src/cmd/ksh93/sh/arith.c b/src/cmd/ksh93/sh/arith.c
--- src/cmd/ksh93/sh/arith.c
+++ src/cmd/ksh93/sh/arith.c
@@ -567,19 +567,32 @@ Sfdouble_t sh_strnum(Shell_t *shp, const char *str, char **ptr, int mode) {
char *last;
if (*str == 0) {
- if (ptr) *ptr = (char *)str;
- return 0;
- }
- errno = 0;
- d = number(str, &last, shp->inarith ? 0 : 10, NULL);
- if (*last) {
- if (*last != '.' || last[1] != '.') {
- d = strval(shp, str, &last, arith, mode);
- Varsubscript = true;
+ d = 0.0;
+ last = (char *)str;
+ } else {
+ d = number(str, &last, shp->inarith ? 0 : 10, NULL);
+ if (*last && !shp->inarith && sh_isstate(shp, SH_INIT)) {
+ // This call is to handle "base#value" literals if we're importing untrusted env vars.
+ d = number(str, &last, 0, NULL);
+ }
+ if (*last) {
+ if (sh_isstate(shp, SH_INIT)) {
+ // Initializing means importing untrusted env vars. Since the string does not appear
+ // to be a recognized numeric literal give up. We can't safely call strval() since
+ // that allows arbitrary expressions which would create a security vulnerability.
+ d = 0.0;
+ } else {
+ if (*last != '.' || last[1] != '.') {
+ d = strval(shp, str, &last, arith, mode);
+ Varsubscript = true;
+ }
+ if (!ptr && *last && mode > 0) {
+ errormsg(SH_DICT, ERROR_exit(1), e_lexbadchar, *last, str);
+ }
+ }
+ } else if (d == 0.0 && *str == '-') {
+ d = -0.0;
}
- if (!ptr && *last && mode > 0) errormsg(SH_DICT, ERROR_exit(1), e_lexbadchar, *last, str);
- } else if (!d && *str == '-') {
- d = -0.0;
}
if (ptr) *ptr = last;
return d;
diff --git a/src/cmd/ksh93/tests/subshell.sh b/src/cmd/ksh93/tests/subshell.sh
--- src/cmd/ksh93/tests/subshell.sh
+++ src/cmd/ksh93/tests/subshell.sh
@@ -856,3 +856,26 @@ for exp in 65535 65536
do got=$($SHELL -c 'x=$(printf "%.*c" '$exp' x); print ${#x}' 2>&1)
[[ $got == $exp ]] || log_error "large command substitution failed" "$exp" "$got"
done
+
+# ==========
+# Verify that importing untrusted env vars does not allow evaluating arbitrary expressions but does
+# recognize all integer literals recognized by ksh.
+expect=8
+actual=$(env SHLVL='7' $SHELL -c 'echo $SHLVL')
+[[ $actual == $expect ]] || log_error "decimal int literal not recognized" "$expect" "$actual"
+
+expect=14
+actual=$(env SHLVL='013' $SHELL -c 'echo $SHLVL')
+[[ $actual == $expect ]] || log_error "leading zeros int literal not recognized" "$expect" "$actual"
+
+expect=4
+actual=$(env SHLVL='2#11' $SHELL -c 'echo $SHLVL')
+[[ $actual == $expect ]] || log_error "base#value int literal not recognized" "$expect" "$actual"
+
+expect=12
+actual=$(env SHLVL='16#B' $SHELL -c 'echo $SHLVL')
+[[ $actual == $expect ]] || log_error "base#value int literal not recognized" "$expect" "$actual"
+
+expect=1
+actual=$(env SHLVL="2#11+x[\$($bin_echo DANGER WILL ROBINSON >&2)0]" $SHELL -c 'echo $SHLVL')
+[[ $actual == $expect ]] || log_error "expression allowed on env var import" "$expect" "$actual"

View File

@ -1,10 +0,0 @@
--- scripts/builtin_documentation.sh.orig 2019-08-30 05:32:36.000000000 -0700
+++ scripts/builtin_documentation.sh 2019-08-30 12:40:24.125856000 -0700
@@ -8,6 +8,6 @@
cmd_name=$(basename "$in_file" .1)
[ "$cmd_name" = ksh ] && continue
echo "const char sh_opt${cmd_name}[] ="
- sed -e 's/\(.*\)/ "\1\\n"/' < "$in_file"
+ sed -e 's/"//g;s/\(.*\)/ "\1\\n"/' < "$in_file"
echo ";"
done

View File

@ -0,0 +1,36 @@
--- src/cmd/std/features/procfs.orig 2017-11-30 22:35:04 UTC
+++ src/cmd/std/features/procfs
@@ -1,6 +1,6 @@
hdr kvm,procinfo,pstat,asm/param
-sys procfs,sysctl
+sys procfs,sysctl,user
lib getprocs
lib kvm_open,kvm_getprocs kvm.h sys/time.h sys/param.h sys/proc.h sys/sysctl.h -lkvm
@@ -10,7 +10,11 @@ mem extern_proc.p_pid,extern_proc.p_star
mem procsinfo64.pi_pri procinfo.h
mem prpsinfo.pr_clname,prpsinfo.pr_cstime,prpsinfo.pr_cstime.tv_sec,prpsinfo.pr_ctime,prpsinfo.pr_cutime,prpsinfo.pr_gid,prpsinfo.pr_lttydev,prpsinfo.pr_ntpid,prpsinfo.pr_pgid,prpsinfo.pr_pgrp,prpsinfo.pr_psargs,prpsinfo.pr_refcount,prpsinfo.pr_rssize,prpsinfo.pr_sid,prpsinfo.pr_sonproc,prpsinfo.pr_start,prpsinfo.pr_start.tv_sec,prpsinfo.pr_starttime,prpsinfo.pr_starttime.tv_sec,prpsinfo.pr_state,prpsinfo.pr_stime,prpsinfo.pr_tgrp,prpsinfo.pr_time,prpsinfo.pr_time.tv_sec,prpsinfo.pr_utime,prpsinfo.pr_zomb,prpsinfo.pr_pctcpu,prpsinfo.pr_cpu,prpsinfo.pr_lwp.pr_pctcpu,prpsinfo.pr_lwp.pr_cpu -D_STRUCTURED_PROC -Dprpsinfo=psinfo sys/types.h sys/procfs.h
+num PIOCPSINFO
+
typ struct.prpsinfo -D_STRUCTURED_PROC -Dprpsinfo=psinfo sys/types.h sys/procfs.h
+typ struct.kinfo_proc sys/types.h sys/procfs.h sys/user.h
+typ struct.kp_proc sys/types.h sys/procfs.h sys/user.h
tst lib_info note{ info(2) kernel table api }end link{
#include <info.h>
@@ -587,11 +591,11 @@ cat{
#define PSS_METHOD PSS_METHOD_getprocs
#endif
-#if !PSS_METHOD && defined(_PS_dir)
+#if !PSS_METHOD && defined(_PS_dir) && (_PS_scan_binary || _num_PIOCPSINFO)
#define PSS_METHOD PSS_METHOD_procfs
#endif
-#if !PSS_METHOD && _hdr_kvm && _sys_sysctl && _lib_kvm_open && _lib_kvm_getprocs
+#if !PSS_METHOD && _hdr_kvm && _sys_sysctl && _lib_kvm_open && _lib_kvm_getprocs && _typ_struct_kinfo_proc && _typ_struct_kp_proc
#define PSS_METHOD PSS_METHOD_kvm
#endif

View File

@ -0,0 +1,12 @@
--- src/cmd/std/pss-kvm.c.orig 2017-11-30 22:35:04 UTC
+++ src/cmd/std/pss-kvm.c
@@ -43,6 +43,9 @@ NoN(pss_kvm)
#if _sys_proc
#include <sys/proc.h>
#endif
+#if _sys_user
+#include <sys/user.h>
+#endif
#include <sys/sysctl.h>
#include <sys/tty.h>

View File

@ -0,0 +1,36 @@
--- src/lib/libast/features/mmap.orig 2020-02-08 10:39:38.000000000 -0800
+++ src/lib/libast/features/mmap 2020-02-08 20:49:37.791733000 -0800
@@ -16,14 +16,7 @@
#define Failed(file) (remove(file),1)
- int
- #if _STD_
- main(int argc, char** argv)
- #else
- main(argc,argv)
- int argc;
- char** argv;
- #endif
+ int main(int argc, char** argv)
{
caddr_t mm;
char *t, *u, *f;
@@ -326,17 +319,12 @@
cat{
/* some systems get it wrong but escape concise detection */
- #ifndef _NO_MMAP
#if __CYGWIN__
#define _NO_MMAP 1
#endif
- #endif
#if _NO_MMAP
#undef _lib_mmap
#undef _lib_mmap64
- #undef _mmap_anon
- #undef _mmap_devzero
- #undef _mmap_worthy
#endif
}end

View File

@ -0,0 +1,23 @@
--- src/lib/libast/features/standards.orig 2020-02-08 10:39:38.000000000 -0800
+++ src/lib/libast/features/standards 2020-02-08 21:58:23.687268000 -0800
@@ -1,5 +1,19 @@
set stdio
-if tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
+# In FreeBSD, definitions like _POSIX_SOURCE and such are used to *limit*
+# functionality to known API; they don't enable anything. The general intent in
+# BSD is to enable everything by default (effectively, providing the
+# _KITCHEN_SINK_SOURCE mentioned below). So we look for that here, but stay
+# careful that we don't get fooled by presence of FreeBSD that underpins some
+# subsystems in Mac OS X; there are other Apple-specific portability hacks
+# elsewhere we should not interfere with.
+if tst note{ FreeBSD }end compile{
+ #include <sys/param.h>
+ #if !defined(__FreeBSD__) || defined(APPLE)
+ #error not a FreeBSD system
+ #endif
+ }end {
+ }
+elif tst note{ _ALL_SOURCE & _POSIX_SOURCE & _POSIX_C_SOURCE & _XOPEN_SOURCE & __EXTENSIONS__ works }end compile{
#define _ALL_SOURCE 1
#define _POSIX_SOURCE 1
#define _POSIX_C_SOURCE 21000101L

View File

@ -0,0 +1,10 @@
--- src/lib/libast/features/vmalloc.orig 2016-02-28 17:09:23 UTC
+++ src/lib/libast/features/vmalloc
@@ -217,7 +217,4 @@ cat{
#if _mmap_anon
#define _mem_mmap_anon 1
#endif
- #if _mmap_devzero
- #define _mem_mmap_zero 1
- #endif
}end

View File

@ -0,0 +1,10 @@
--- src/lib/libast/features/wchar.orig 2017-11-30 22:35:04 UTC
+++ src/lib/libast/features/wchar
@@ -6,6 +6,7 @@ set include .
cat{
#ifndef _AST_WCHAR_H
#define _AST_WCHAR_H 1
+ #define _STDFILE_DECLARED
}end
lib mbstowcs,wctomb,wcscmp,wcscoll,wcslen,wcstombs,wcsxfrm,wcwidth stdlib.h stdio.h wchar.h

View File

@ -0,0 +1,17 @@
--- src/lib/libast/port/astcopy.c.orig 2016-02-28 17:09:23 UTC
+++ src/lib/libast/port/astcopy.c
@@ -30,14 +30,10 @@
#include <ast.h>
#include <ast_mmap.h>
-#if _mmap_worthy > 1
-
#include <ls.h>
#define MAPSIZE (1024*256)
-#endif
-
#undef BUFSIZ
#define BUFSIZ 4096

View File

@ -0,0 +1,12 @@
--- src/lib/libast/sfio/sfhdr.h.orig 2016-02-28 17:09:23 UTC
+++ src/lib/libast/sfio/sfhdr.h
@@ -209,9 +209,6 @@
/* see if we can use memory mapping for io */
#if _LARGEFILE64_SOURCE && !_lib_mmap64
-#undef _mmap_worthy
-#endif
-#if !_mmap_worthy
#undef _hdr_mman
#undef _sys_mman
#endif

View File

@ -0,0 +1,24 @@
--- src/lib/libast/sfio/sfseek.c.orig 2020-02-08 10:39:38.000000000 -0800
+++ src/lib/libast/sfio/sfseek.c 2020-02-09 20:01:11.420655000 -0800
@@ -204,18 +204,9 @@
#ifdef MAP_TYPE
if(f->bits&SF_MMAP)
{ /* if mmap is not great, stop mmaping if moving around too much */
-#if _mmap_worthy < 2
- if((f->next - f->data) < ((f->endb - f->data)/4) )
- { SFSETBUF(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND);
- hardseek = 1; /* this forces a hard seek below */
- }
- else
-#endif
- { /* for mmap, f->here can be virtual except for hardseek */
- newpos(f,p);
- if(!hardseek)
- goto done;
- }
+ newpos(f,p);
+ if(!hardseek)
+ goto done;
}
#endif

View File

@ -0,0 +1,87 @@
--- src/lib/libast/string/strexpr.c.orig 2017-11-30 22:35:04 UTC
+++ src/lib/libast/string/strexpr.c
@@ -44,7 +44,7 @@
#define peekchr(ex) (*(ex)->nextchr)
#define ungetchr(ex) ((ex)->nextchr--)
-#define error(ex,msg) return(seterror(ex,msg))
+#define err(ex,msg) return(seterror(ex,msg))
typedef struct /* expression handle */
{
@@ -87,7 +87,7 @@ expr(register Expr_t* ex, register int p
case 0:
ungetchr(ex);
if (!precedence) return(0);
- error(ex, "more tokens expected");
+ err(ex, "more tokens expected");
case '-':
n = -expr(ex, 13);
break;
@@ -113,17 +113,17 @@ expr(register Expr_t* ex, register int p
case 0:
goto done;
case ')':
- if (!precedence) error(ex, "too many )'s");
+ if (!precedence) err(ex, "too many )'s");
goto done;
case '(':
n = expr(ex, 1);
if (getchr(ex) != ')')
{
ungetchr(ex);
- error(ex, "closing ) expected");
+ err(ex, "closing ) expected");
}
gotoperand:
- if (operand) error(ex, "operator expected");
+ if (operand) err(ex, "operator expected");
operand = 1;
continue;
case '?':
@@ -140,7 +140,7 @@ expr(register Expr_t* ex, register int p
if (getchr(ex) != ':')
{
ungetchr(ex);
- error(ex, ": expected for ? operator");
+ err(ex, ": expected for ? operator");
}
if (n)
{
@@ -189,7 +189,7 @@ expr(register Expr_t* ex, register int p
break;
case '=':
case '!':
- if (peekchr(ex) != '=') error(ex, "operator syntax error");
+ if (peekchr(ex) != '=') err(ex, "operator syntax error");
if (precedence > 7) goto done;
getchr(ex);
x = expr(ex, 8);
@@ -237,7 +237,7 @@ expr(register Expr_t* ex, register int p
if (precedence > 11) goto done;
x = expr(ex, 12);
if (c == '*') n *= x;
- else if (x == 0) error(ex, "divide by zero");
+ else if (x == 0) err(ex, "divide by zero");
else if (c == '/') n /= x;
else n %= x;
break;
@@ -246,15 +246,15 @@ expr(register Expr_t* ex, register int p
pos = --ex->nextchr;
if (isdigit(c)) n = strton(ex->nextchr, &ex->nextchr, NiL, 0);
else if (ex->convert) n = (*ex->convert)(ex->nextchr, &ex->nextchr, ex->handle);
- if (ex->nextchr == pos) error(ex, "syntax error");
+ if (ex->nextchr == pos) err(ex, "syntax error");
goto gotoperand;
}
if (ex->errmsg) return(0);
- if (!operand) error(ex, "operand expected");
+ if (!operand) err(ex, "operand expected");
}
done:
ungetchr(ex);
- if (!operand) error(ex, "operand expected");
+ if (!operand) err(ex, "operand expected");
return(n);
}

View File

@ -1,3 +1,6 @@
@shell bin/ksh%%93%%
bin/shcomp%%93%%
man/man1/ksh%%93%%.1.gz
share/examples/ksh93/dirs
share/examples/ksh93/popd
share/examples/ksh93/pushd