after enough complaints by POSIX sh advocates,
• make parsing numbers with leading digit-zero as octal independent of mksh/lksh and dependent on set -o posix; adjust manpages to match • warn about these changes and why mksh uses 32-bit consistent arithmetics and point people to lksh for host-long undefined-behaviour arithmetics • point out, explicitly, that it is *legal* for the operating environment to make 'print $((2147483647 + 1))' (on a 32-bit system; adjust for a 64-bit system) to run 'rm -rf ~ /' instead
This commit is contained in:
parent
496988e27a
commit
dc94c3d205
7
Makefile
7
Makefile
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/Makefile,v 1.119 2013/04/27 18:22:47 tg Exp $
|
# $MirOS: src/bin/mksh/Makefile,v 1.120 2013/04/27 18:50:21 tg Exp $
|
||||||
#-
|
#-
|
||||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||||
# 2011, 2012, 2013
|
# 2011, 2012, 2013
|
||||||
@ -104,6 +104,9 @@ test-build-lksh: .PHONY
|
|||||||
cd ${.CURDIR} && exec ${MAKE} lksh.cat1 test-build \
|
cd ${.CURDIR} && exec ${MAKE} lksh.cat1 test-build \
|
||||||
_TBF=-L USE_PRINTF_BUILTIN=0
|
_TBF=-L USE_PRINTF_BUILTIN=0
|
||||||
|
|
||||||
|
bothmans: .PHONY
|
||||||
|
cd ${.CURDIR} && exec ${MAKE} MAN='lksh.1 mksh.1' __MANALL
|
||||||
|
|
||||||
cleandir: clean-extra
|
cleandir: clean-extra
|
||||||
|
|
||||||
clean-extra: .PHONY
|
clean-extra: .PHONY
|
||||||
@ -132,7 +135,7 @@ CLEANFILES+= ${MAN:S/$/.txt/} ${MAN:S/$/.txt.gz/}
|
|||||||
CATS_KW= mksh, ksh, sh
|
CATS_KW= mksh, ksh, sh
|
||||||
CATS_TITLE_mksh_1=mksh - The MirBSD Korn Shell
|
CATS_TITLE_mksh_1=mksh - The MirBSD Korn Shell
|
||||||
cats: ${MANALL} ${MANALL:S/.cat/.ps/}
|
cats: ${MANALL} ${MANALL:S/.cat/.ps/}
|
||||||
.if "${MANALL:Nmksh.cat1}" != ""
|
.if "${MANALL:Nlksh.cat1:Nmksh.cat1}" != ""
|
||||||
. error Adjust here.
|
. error Adjust here.
|
||||||
.endif
|
.endif
|
||||||
.for _m _n in mksh 1
|
.for _m _n in mksh 1
|
||||||
|
25
check.t
25
check.t
@ -1,4 +1,4 @@
|
|||||||
# $MirOS: src/bin/mksh/check.t,v 1.607 2013/04/26 21:22:42 tg Exp $
|
# $MirOS: src/bin/mksh/check.t,v 1.608 2013/04/27 18:50:21 tg Exp $
|
||||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||||
@ -3779,22 +3779,17 @@ expected-stdout:
|
|||||||
---
|
---
|
||||||
name: integer-base-check-flat
|
name: integer-base-check-flat
|
||||||
description:
|
description:
|
||||||
Check behaviour does not match POSuX, because a not type-safe
|
Check behaviour does not match POSuX (except if set -o posix),
|
||||||
scripting language has *no* business interpreting "010" as octal
|
because a not type-safe scripting language has *no* business
|
||||||
category: shell:legacy-no
|
interpreting the string "010" as octal numer eight (dangerous).
|
||||||
stdin:
|
stdin:
|
||||||
echo :$((10)).$((010)).$((0x10)).
|
echo 1 "$("$__progname" -c 'echo :$((10))/$((010)),$((0x10)):')" .
|
||||||
|
echo 2 "$("$__progname" -o posix -c 'echo :$((10))/$((010)),$((0x10)):')" .
|
||||||
|
echo 3 "$("$__progname" -o sh -c 'echo :$((10))/$((010)),$((0x10)):')" .
|
||||||
expected-stdout:
|
expected-stdout:
|
||||||
:10.10.16.
|
1 :10/10,16: .
|
||||||
---
|
2 :10/8,16: .
|
||||||
name: integer-base-check-flat-legacy
|
3 :10/10,16: .
|
||||||
description:
|
|
||||||
Check behaviour matches POSuX for LEGACY KSH
|
|
||||||
category: shell:legacy-yes
|
|
||||||
stdin:
|
|
||||||
echo :$((10)).$((010)).$((0x10)).
|
|
||||||
expected-stdout:
|
|
||||||
:10.8.16.
|
|
||||||
---
|
---
|
||||||
name: integer-base-check-numeric-from
|
name: integer-base-check-numeric-from
|
||||||
description:
|
description:
|
||||||
|
33
lksh.1
33
lksh.1
@ -1,7 +1,22 @@
|
|||||||
.\" $MirOS: src/bin/mksh/lksh.1,v 1.1 2013/04/27 18:13:58 tg Exp $
|
.\" $MirOS: src/bin/mksh/lksh.1,v 1.2 2013/04/27 18:50:24 tg Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013
|
.\" Copyright (c) 2008, 2009, 2010, 2012, 2013
|
||||||
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
|
.\" Thorsten “mirabilos” Glaser <tg@mirbsd.org>
|
||||||
|
.\"
|
||||||
|
.\" Provided that these terms and disclaimer and all copyright notices
|
||||||
|
.\" are retained or reproduced in an accompanying document, permission
|
||||||
|
.\" is granted to deal in this work without restriction, including un‐
|
||||||
|
.\" limited rights to use, publicly perform, distribute, sell, modify,
|
||||||
|
.\" merge, give away, or sublicence.
|
||||||
|
.\"
|
||||||
|
.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
|
||||||
|
.\" the utmost extent permitted by applicable law, neither express nor
|
||||||
|
.\" implied; without malicious intent or gross negligence. In no event
|
||||||
|
.\" may a licensor, author or contributor be held liable for indirect,
|
||||||
|
.\" direct, other damage, loss, or other issues arising in any way out
|
||||||
|
.\" of dealing in the work, even if advised of the possibility of such
|
||||||
|
.\" damage or existence of a defect, except proven that it results out
|
||||||
|
.\" of said person’s immediate fault when using the work as intended.
|
||||||
.\"-
|
.\"-
|
||||||
.\" Try to make GNU groff and AT&T nroff more compatible
|
.\" Try to make GNU groff and AT&T nroff more compatible
|
||||||
.\" * ` generates ‘ in gnroff, so use \`
|
.\" * ` generates ‘ in gnroff, so use \`
|
||||||
@ -149,11 +164,15 @@
|
|||||||
.Ek
|
.Ek
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
is a command interpreter intended exclusive for running legacy
|
is a command interpreter intended exclusively for running legacy
|
||||||
shell scripts.
|
shell scripts.
|
||||||
It is built on
|
It is built on
|
||||||
.Nm mksh ;
|
.Nm mksh ;
|
||||||
refer to its manual page for details on the scripting language.
|
refer to its manual page for details on the scripting language.
|
||||||
|
It is recommended to port scripts to
|
||||||
|
.Nm mksh
|
||||||
|
instead of relying on legacy or idiotic POSIX-mandated behaviour,
|
||||||
|
since the MirBSD Korn Shell scripting language is much more consistent.
|
||||||
.Sh LEGACY MODE
|
.Sh LEGACY MODE
|
||||||
.Nm
|
.Nm
|
||||||
has the following differences from
|
has the following differences from
|
||||||
@ -212,9 +231,6 @@ unlike
|
|||||||
.Nm ksh ,
|
.Nm ksh ,
|
||||||
does not keep file descriptors \*(Gt 2 private.
|
does not keep file descriptors \*(Gt 2 private.
|
||||||
.It
|
.It
|
||||||
.Nm
|
|
||||||
parses leading-zero numbers as octal (base 8).
|
|
||||||
.It
|
|
||||||
Integers use the host C environment's
|
Integers use the host C environment's
|
||||||
.Vt long
|
.Vt long
|
||||||
type, not
|
type, not
|
||||||
@ -246,13 +262,6 @@ tries to make a cross between a legacy bourne/posix compatibl-ish
|
|||||||
shell and a legacy pdksh-alike but
|
shell and a legacy pdksh-alike but
|
||||||
.Dq legacy
|
.Dq legacy
|
||||||
is not exactly specified.
|
is not exactly specified.
|
||||||
Parsing numbers with leading zero digits or
|
|
||||||
.Dq 0x
|
|
||||||
is relatively recent in all
|
|
||||||
.Nm pdksh
|
|
||||||
derivates, but supported here for completeness.
|
|
||||||
It might make sense to make this a run-time option, but
|
|
||||||
that might also be overkill.
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Ic set
|
.Ic set
|
||||||
|
27
mksh.1
27
mksh.1
@ -1,4 +1,4 @@
|
|||||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.310 2013/04/26 21:22:47 tg Exp $
|
.\" $MirOS: src/bin/mksh/mksh.1,v 1.311 2013/04/27 18:50:24 tg Exp $
|
||||||
.\" $OpenBSD: ksh.1,v 1.146 2013/03/18 11:10:52 mpi Exp $
|
.\" $OpenBSD: ksh.1,v 1.146 2013/03/18 11:10:52 mpi Exp $
|
||||||
.\"-
|
.\"-
|
||||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||||
@ -74,7 +74,7 @@
|
|||||||
.\" with -mandoc, it might implement .Mx itself, but we want to
|
.\" with -mandoc, it might implement .Mx itself, but we want to
|
||||||
.\" use our own definition. And .Dd must come *first*, always.
|
.\" use our own definition. And .Dd must come *first*, always.
|
||||||
.\"
|
.\"
|
||||||
.Dd $Mdocdate: April 26 2013 $
|
.Dd $Mdocdate: April 27 2013 $
|
||||||
.\"
|
.\"
|
||||||
.\" Check which macro package we use, and do other -mdoc setup.
|
.\" Check which macro package we use, and do other -mdoc setup.
|
||||||
.\"
|
.\"
|
||||||
@ -2563,9 +2563,14 @@ Additionally, base-16 integers may be specified by prefixing them with
|
|||||||
in all forms of arithmetic expressions, except as numeric arguments to the
|
in all forms of arithmetic expressions, except as numeric arguments to the
|
||||||
.Ic test
|
.Ic test
|
||||||
built-in command.
|
built-in command.
|
||||||
It is discouraged to prefix numbers with a sole zero
|
Prefixing numbers with a sole digit zero
|
||||||
.Pq Sq 0 ,
|
.Pq Sq 0
|
||||||
because some shells may interpret them as base-8 integers.
|
leads to the shell interpreting it as base-8 integer in
|
||||||
|
.Ic posix
|
||||||
|
mode
|
||||||
|
.Em only ;
|
||||||
|
historically, (pd)ksh has never done so either anyway,
|
||||||
|
and it's unsafe to do that, but POSIX demands it nowadays.
|
||||||
As a special
|
As a special
|
||||||
.Nm mksh
|
.Nm mksh
|
||||||
extension, numbers to the base of one are treated as either (8-bit
|
extension, numbers to the base of one are treated as either (8-bit
|
||||||
@ -6334,6 +6339,16 @@ Use co-processes instead.
|
|||||||
foo \*(Ba bar \*(Ba read baz # will not change $baz
|
foo \*(Ba bar \*(Ba read baz # will not change $baz
|
||||||
foo \*(Ba bar \*(Ba& read \-p baz # will, however, do so
|
foo \*(Ba bar \*(Ba& read \-p baz # will, however, do so
|
||||||
.Ed
|
.Ed
|
||||||
|
.Pp
|
||||||
|
.Nm mksh
|
||||||
|
provides a consistent set of 32-bit integer arithmetics, both signed
|
||||||
|
and unsigned, with defined wraparound and sign of the result of a modulo
|
||||||
|
operation, even (defying POSIX) on 64-bit systems.
|
||||||
|
If you require 64-bit integer arithmetics, use
|
||||||
|
.Nm lksh Pq legacy mksh
|
||||||
|
instead, but be aware that, in POSIX, it's legal for the OS to make
|
||||||
|
.Li print $((2147483647 + 1))
|
||||||
|
delete all files on your system, as it's Undefined Behaviour.
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
Suspending (using \*(haZ) pipelines like the one below will only suspend
|
Suspending (using \*(haZ) pipelines like the one below will only suspend
|
||||||
the currently running part of the pipeline; in this example,
|
the currently running part of the pipeline; in this example,
|
||||||
@ -6345,7 +6360,7 @@ $ /bin/sleep 666 && echo fubar
|
|||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
This document attempts to describe
|
This document attempts to describe
|
||||||
.Nm mksh\ R45
|
.Nm mksh\ R46
|
||||||
and up,
|
and up,
|
||||||
compiled without any options impacting functionality, such as
|
compiled without any options impacting functionality, such as
|
||||||
.Dv MKSH_SMALL ,
|
.Dv MKSH_SMALL ,
|
||||||
|
6
var.c
6
var.c
@ -27,7 +27,7 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.170 2013/04/07 14:11:54 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.171 2013/04/27 18:50:25 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Variables
|
* Variables
|
||||||
@ -495,14 +495,12 @@ getint(struct tbl *vp, mksh_ari_u *nump, bool arith)
|
|||||||
base = 16;
|
base = 16;
|
||||||
have_base = true;
|
have_base = true;
|
||||||
}
|
}
|
||||||
#ifdef MKSH_LEGACY_MODE
|
if (Flag(FPOSIX) && arith && s[0] == '0' && ksh_isdigit(s[1]) &&
|
||||||
if (arith && s[0] == '0' && ksh_isdigit(s[1]) &&
|
|
||||||
!(vp->flag & ZEROFIL)) {
|
!(vp->flag & ZEROFIL)) {
|
||||||
/* interpret as octal (deprecated) */
|
/* interpret as octal (deprecated) */
|
||||||
base = 8;
|
base = 8;
|
||||||
have_base = true;
|
have_base = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
while ((c = *s++)) {
|
while ((c = *s++)) {
|
||||||
if (c == '-') {
|
if (c == '-') {
|
||||||
neg = true;
|
neg = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user