Skip to content

Commit

Permalink
Rebased against ksh from OpenBSD 5.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
dimkr committed Apr 5, 2016
1 parent aedb7c4 commit d1eafa7
Show file tree
Hide file tree
Showing 40 changed files with 1,639 additions and 1,635 deletions.
253 changes: 2 additions & 251 deletions NOTES
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$OpenBSD: NOTES,v 1.12 2013/11/28 10:33:37 sobrado Exp $
$OpenBSD: NOTES,v 1.14 2016/01/29 11:50:40 tb Exp $

General features of at&t ksh88 that are not (yet) in pdksh:
- exported aliases and functions (not in ksh93).
Expand Down Expand Up @@ -180,7 +180,7 @@ Known differences between pdksh & at&t ksh (that are not likely to change)
(POSIX does not require the setting of variables to null so applications
shouldn't rely on this).
- in pdksh, ! substitution done before variable substitution; in at&t ksh
it is done after substitution (and therefor may do ! substitutions on
it is done after substitution (and therefore may do ! substitutions on
the result of variable substitutions). POSIX doesn't say which is to be
done.
- pwd: in at&t ksh, it ignores arguments; in pdksh, it complains when given
Expand Down Expand Up @@ -244,255 +244,6 @@ Oddities in ksh (pd & at&t):
- undocumented at&t ksh feature: FPATH is searched after PATH if no
executable is found, even if typeset -uf wasn't used.

at&t ksh bugs:
[various versions:
MIPS m120 RISC/os 5.0: Version 11/16/88d
Dec alpha osf/1 v1.3: OSF/1 Version 11/16/88d NLS
HP pa HP-UX 9.01: Version 11/16/88
]
- (only hpux)
$ _[2]=hi
Bus error (core dumped)
- (only riscos, hpux)
$ typeset x[
$
- (only osf/1)
$ A=B cat << EOF
.$A.
EOF
Segmentation fault(coredump)
$
- (only osf/1)
$ read "?foo "
foo Foo
$ set | grep Foo
=Foo
$
- (all)
$ typeset -i A
$ typeset -L3 A
$ typeset -l A
Illegal instruction (core dumped)
- (all)
$ for i in a b c ; do echo $i, ${i[2]}, ${i[10]} ; done
a, ,
a, , b
a, , c
$
- (all)
$ echo ${abc:-G { I } K }
G { I K }
$
$ abc=hi
$ echo ${abc:-G { I } K }
hi K }
$
The second echo should only have printed `hi'.
- (all)
$ echo ${abc:- > foo}
syntax error: > unexpected
$
- (all? hpux) read reads too much from pipe (when pipe isn't stdin)
print 'hi\nthere' | ksh 8<&0 0< /dev/tty
$ read -u8 x
$ print $x
hi
$ cat 0<&8
$ read -u8 y
$ print $y
there
$
- (all)
$ umask 0
$ umask
00
$
- (osf, mips, !hpux)
$ exec alias
alias: not found
(shell dead)
- (all) non-white space IFS in non-substitution not preserved
$ IFS="$IFS:"
$ echo : "$@" # this is ok
:
$ echo :"$@" # this should print : too (me thinks)

$
- (only osf/1)
$ set +m
$ sleep 1 & # wait for a sec or two
$ jobs
Memory fault (core dumped)
- (all)
$ (sleep 1 & echo hi) &
[1] 123
$ [1] 234
hi
- (osf/1, mips)
$ getopts abc optc -a -b -c
$ getopts abc optc -a -b -c
$ getopts abc optc -a
Memory fault (core dumped)
- (osf/1) POSIX says OPTIND shall be initialized to 1
$ echo $OPTIND
0
$
- (osf/1 + others?)
$ typeset -ri r=10
$ let r=12
$ echo $r
12
$
- (osf/1 + others?)
$ typeset -i a
$ typeset -L3 a
Memory fault (core dumped)
- (osf/1 + others?): -L strips leading \ \t\n\r, -R only strips trailing
spaces
$ typeset -L3 x
$ x=' ^I^J^M 2'
$ echo "($x)"
(2 )
$ typeset -R3 y
$ x='2^I^J^M '
$ echo "($x)"
(^I^J^M)
$
- (osf/1 + others?)
$ typeset +i RANDOM
Memory fault (core dumped)
- (osf/1 + others?): -L/-R/-Z clear -l/-u after assignment and vise versa
$ typeset -u x=ab
$ echo "($x)"
(AB)
$ typeset -L4 x=def
$ echo "($x)"
(DEF )
$ typeset | grep ' x$'
leftjust 4 x
$
$ typeset -L4 x=def
$ echo "($x)"
(def )
$ typeset -u x=ab
$ echo "($x)"
(AB )
$ typeset | grep ' x$'
uppercase x
$
$ typeset -i x
$ x='2()'
$ x='()'
$ x='2(4)'
- (osf/1, others?)
$ unset foo
$ echo "${foo:-"*"}"
<results of * expansion>
$
- (osf/1, others?)
$ alias blah
blah: alias not found
$ alias -x blah | grep blah
blah
$ type blah
Memory fault (core dumped)
- (osf/1, others?)
$ trap 'echo hi; false' ERR
$ false
hi
hi
....
Memory fault (core dumped)
- (osf/1, others?)
$ typeset +i ERRNO
Memory fault (core dumped)
- (osf/1, others?)
$ X=abcdef
$ echo ${X#a{b,c}e} # does not match {} inside word part of ${..#..}
abcdefe}
$
- (osf/1, others?)
$ x=f=abcdef
$ echo ${f#a|abc}
def
$ echo ${f#abc|a}
bcdef
$ echo ${f#abc|a|d}
abcdef
$
- (osf/1, hp-ux, others?)
$ i() echo hi
$ typeset -f
function i
{
hi
$
- (osf/1, others?)
$ function X {
echo start of X
function Y {
echo in Y
}
echo end of X
}
$ X
start of X
end of X
$ typeset -f
function X
{
echo start of X
function Y {
echo in Y
}
echo end of X
}
function Y
{
echo in Y
echo end of X
}
}
$
- (osf/1, others?)
$ while read x; do print -r "A $x"; done |&
[1] 18212
$ exec 8<&p
$ kill %1
Memory fault
- (osf/1, others?) Error only happens for builtin commands (/bin/echo works)
$ while read x; do print -r "A $x"; done |&
[1] 18212
$ echo hi <&p
hi
$ echo hi <&p
ksh: p: bad file unit number
$ while read x; do print -r "A $x"; done |&
ksh: process already exists
$
- (osf/1, others?) in restricted shells, command -p should not work.
$ PATH=/tmp ksh -r
$ print hi | command -p cat -n
1 hi
$
- (osf/1, others?) error message wrong for autoload files that don't define
functions
$ FPATH=/tmp
$ echo echo hi there > /tmp/aja
$ aja
hi there
ksh: echo: not found
$
- (SunOS M-12/28/93d):
$ cat -n << X $(
> echo foo
> )
> X
> echo bar
)
./ksh93: X: cannot open [No such file or directory]
Memory fault (core dumped)

POSIX sh questions (references are to POSIX 1003.2-1992)
- arithmetic expressions: how are empty expressions treated?
(eg, echo $(( ))). at&t ksh (and now pdksh) echo 0.
Expand Down
5 changes: 1 addition & 4 deletions PROJECTS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$OpenBSD: PROJECTS,v 1.7 2013/11/28 10:33:37 sobrado Exp $
$OpenBSD: PROJECTS,v 1.8 2015/09/14 09:42:33 nicm Exp $

Things to be done in pdksh (see also the NOTES file):

Expand Down Expand Up @@ -109,6 +109,3 @@ Things to be done in pdksh (see also the NOTES file):

* teach shf_vfprintf() about long long's (%lld); also make %p use
long longs if appropriate.

* decide wether to keep currently disabled FP stuff in shf.c; if
not, eliminate ksh_limval.h (moving BITS to var.c).
33 changes: 32 additions & 1 deletion alloc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: alloc.c,v 1.8 2008/07/21 17:30:08 millert Exp $ */
/* $OpenBSD: alloc.c,v 1.14 2015/12/14 13:59:42 tb Exp $ */
/*
* Copyright (c) 2002 Marc Espie.
*
Expand Down Expand Up @@ -28,6 +28,9 @@
* area-based allocation built on malloc/free
*/

#include <stdint.h>
#include <stdlib.h>

#include "sh.h"

struct link {
Expand Down Expand Up @@ -62,6 +65,10 @@ alloc(size_t size, Area *ap)
{
struct link *l;

/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
internal_errorf(1, "unable to allocate memory");

l = malloc(sizeof(struct link) + size);
if (l == NULL)
internal_errorf(1, "unable to allocate memory");
Expand All @@ -74,6 +81,26 @@ alloc(size_t size, Area *ap)
return L2P(l);
}

/*
* Copied from calloc().
*
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
*/
#define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4))

void *
areallocarray(void *ptr, size_t nmemb, size_t size, Area *ap)
{
/* condition logic cloned from calloc() */
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
nmemb > 0 && SIZE_MAX / nmemb < size) {
internal_errorf(1, "unable to allocate memory");
}

return aresize(ptr, nmemb * size, ap);
}

void *
aresize(void *ptr, size_t size, Area *ap)
{
Expand All @@ -82,6 +109,10 @@ aresize(void *ptr, size_t size, Area *ap)
if (ptr == NULL)
return alloc(size, ap);

/* ensure that we don't overflow by allocating space for link */
if (size > SIZE_MAX - sizeof(struct link))
internal_errorf(1, "unable to allocate memory");

l = P2L(ptr);
lprev = l->prev;
lnext = l->next;
Expand Down
Loading

0 comments on commit d1eafa7

Please sign in to comment.