Commit Graph

884 Commits

Author SHA1 Message Date
tg c3e794c4d0 rework string pooling; disable our own (rely on compiler’s)…
• if HAVE_STRING_POOLING is set to 1
• if HAVE_STRING_POOLING is set to 2 and not GCC < 4 is used
• if HAVE_STRING_POOLING is not set to 0 and LLVM or GCC >= 4 is used

Closes: LP#1580348
2016-07-25 00:04:48 +00:00
tg e8bbf79d8c invent builtin flags instead of special-casing cat and printf for prefer-external-over-builtin stuff 2016-07-24 23:10:04 +00:00
tg 8370c0dd4d experimentally use MKSH_CLRTOEOL_STRING instead of lots of spaces followed
by lots of backspaces for many clearing scenarios; requested by tmux user
slagtc on IRC
2016-07-12 23:07:10 +00:00
KO Myung-Hun 0d730e1ad9 Merge remote-tracking branch 'mksh/master' 2016-06-29 08:17:29 +09:00
tg a41a62dad7 efficient $(<<<foo) and $(<<EOF … ) implementation, requested by izabera 2016-06-26 00:44:59 +00:00
tg 58f36a9f3a increase default input line, from PLD Linux
(for as long as we still have the size static, and !MKSH_SMALL)
2016-06-25 23:49:50 +00:00
tg 9ab9ee194c fix shf.c-internal buffer overread on printing digits,
introduced by the utf_skipcols()-related fixes, more
specifically the check for combining multibyte characters
past end of given width (bogus mixed-up semantics we have here)
by reïntroducing the NUL byte from commitid 1005474EE1E4024A4E4
2016-05-17 15:36:35 +00:00
KO Myung-Hun e8966076c8 Merge remote-tracking branch 'mksh/master' 2016-05-06 17:12:52 +09:00
tg 92833fc6ce fix utf_widthadj/utf_skipcols handling for the remaining cases I can spot 2016-05-05 22:56:15 +00:00
tg 3da248755a bump 2016-04-14 15:38:38 +00:00
tg 4c4131dddf commitid 10056D5D8AF01B31531 broke fix for Debian #783978 (add testsuite) 2016-04-09 13:55:12 +00:00
KO Myung-Hun 68f6e899ef Merge tag 'mksh-R52c' 2016-03-05 14:59:34 +09:00
tg 4ccfd5fab5 document upcoming set +o changes; bump 2016-03-04 18:28:42 +00:00
tg cb0604767f address latest Debian gcc-snapshot’s warnings (some actual bugs!) 2016-03-04 14:26:16 +00:00
tg c2bdb1b9dd check not-begun heredocs at EOF earlier
izabera reported they were not caught with “set -n”
2016-03-01 18:30:05 +00:00
tg f23ed68f00 clean up, avoid aliasing concerns in non-debug case 2016-02-26 21:53:37 +00:00
tg 3b5f9c744c I didn’t like the code behind command -[Vv] and whence, so I rewrote it.
Bugreport by Martijn Dekker <martijn@inlv.org> about POSIX non-compliance
2016-02-26 20:56:45 +00:00
tg a3c28ebd67 plug a few display problems with special parameter name expansions
reported by Stéphane Chazelas
2016-02-26 18:48:14 +00:00
KO Myung-Hun e9364a4318 Merge remote-tracking branch 'mksh/master' 2016-02-25 14:56:35 +09:00
tg 2a3773b70b share structures better, less (void *) casts when we can stay typed 2016-02-24 02:08:39 +00:00
tg f0a042f070 implement mmap-using mechanism to catch buffer underruns inside mksh
(pulls stdio, is rather BSD-specific and memory-hungry and a bit slow)
2016-02-24 01:44:46 +00:00
KO Myung-Hun 36ea6b5f88 Merge remote-tracking branch 'mksh/master' 2016-01-24 16:43:45 +09:00
KO Myung-Hun 6eb125c18a Merge commit '91ae6ad199035b1cf' 2016-01-24 16:36:38 +09:00
tg 7c58621bc7 so, GCC is a real bitch 2016-01-21 19:58:13 +00:00
tg 27179454a9 hotfix for newer GCC 2016-01-21 19:38:09 +00:00
tg 188691d285 save 200 bytes off .text by revisiting string pooling
also, forgotten version bump
2016-01-21 18:24:45 +00:00
tg 61f7661b92 fix errno in print/echo builtin; optimise (with partial rewrite) 2016-01-20 21:34:13 +00:00
tg 046d8e5b7a align with future POSIX on http://austingroupbugs.net/view.php?id=351
with accepted interpretation (*sigh*); merge VARASN|ARRAYVAR→CMDASN
2016-01-19 23:12:15 +00:00
tg c51e067e62 incorporate more feedback from schily 2016-01-14 23:18:11 +00:00
tg 1b0e4f54cb permit 'read -A/-a arr[idx]' as long as only one element is read;
fix corruption of array indicēs with this construct (LP#1533396)
2016-01-14 22:49:33 +00:00
tg 2492c5692b incorporate suggestions by J�rg Schilling 2016-01-13 17:20:52 +00:00
tg 4059e105a2 fstat(2) after open(2) for set -C case when initial stat(2) was !S_ISREG
to fix race condition as suggested by jilles
2015-12-31 21:03:47 +00:00
KO Myung-Hun 0c41f2fdc8 Merge remote-tracking branch 'mksh/master' 2015-12-13 17:59:43 +09:00
tg b2b0c0bbb6 update for recent changes 2015-12-12 22:25:15 +00:00
KO Myung-Hun 788fdcd188 Merge remote-tracking branch 'mksh/master' 2015-10-26 11:24:15 +09:00
tg 1a4f644d6e save ~1½K from the bootfloppy by reusing MirBSD libkern wcwidth(3)
but don’t bother for this for the regular /bin/mksh either
to keep the generic code path tested well
2015-10-24 19:45:23 +00:00
KO Myung-Hun 780f220e23 Merge remote-tracking branch 'mksh/master'
Conflicts:
    check.t
    exec.c
    sh.h
2015-10-11 19:42:38 +09:00
tg cef386fb60 make “source” into a built-in command (keepasn, to match ksh93 and “dot”);
remove the “stop” alias and drop old Android and OS/2 hacks and auto-unalias
2015-10-09 21:36:59 +00:00
tg fc48729336 tweak some iop/conservative_fds-related things I picked up while thinking lksh 2015-10-09 19:29:50 +00:00
tg af35e9a6de revert most of commitid 3ec342c92b3a8874 and fixup the rest;
this should bring us closer to POSIX again
2015-10-09 17:48:53 +00:00
tg 3fc8b5eb94 partial oksh sync, up to commit 80be547da108d5c241ae068290ca3e331446aa41? 2015-10-09 16:11:19 +00:00
tg eb9050b8f8 stop using issetugid(2) for ±p check as it’s probably not the right tool 2015-10-05 17:59:00 +00:00
KO Myung-Hun bd9de444e3 Merge remote-tracking branch 'mksh/master' 2015-09-12 12:50:57 +09:00
tg ed5cb56849 replace the code related to << changes and <<< with cleaner code,
fixing a few bugs also (including new testcases, except x=<< issue)
2015-09-06 19:47:01 +00:00
tg edc2acd61d fix tree printing multiple heredocs in one command, bug found by izabera 2015-09-05 20:20:48 +00:00
tg 4adcfe8b58 oksh sync, simplify *all* if(x)free(x); constructs, simplify x_push() and sync boilerplate while here 2015-09-05 19:19:12 +00:00
KO Myung-Hun df20ee1fff Merge remote-tracking branch 'mksh/master'
Conflicts:
	check.t
	main.c
2015-08-15 23:45:52 +09:00
tg 1b8b792b7e quote path separator if ; in some cases; pointed out by komh 2015-08-13 22:06:23 +00:00
tg c674e71377 be more careful with signals and errorlevels; bounds-check them better;
don’t trust the OS as POSuX comes up with more-than-8-bit exit codes now;
also, one more int → bool
2015-08-13 21:38:19 +00:00
KO Myung-Hun 4c61aeebe5 Use upstream style macro/function names
modified:   edit.c
    modified:   eval.c
    modified:   exec.c
    modified:   main.c
    modified:   misc.c
    modified:   sh.h
2015-07-21 16:30:47 +09:00
KO Myung-Hun 834349f3be Merge remote-tracking branch 'mksh/master'
Conflicts:
	Build.sh
	check.pl
	check.t
	edit.c
	emacsfn.h
	exec.c
	funcs.c
	main.c
	misc.c
	sh.h
	var.c
2015-07-21 16:30:46 +09:00
tg ba8a6e9461 merge OS/2 style PATH (absolute with drive letters, ‘;’ as separator)
From: KO Myung-Hun <komh@chollian.net>
2015-07-10 19:36:38 +00:00
tg edf76ec8e6 harden the crlf vs lf tests even more; use binary mode explicitly on OS/2 2015-07-09 20:52:43 +00:00
tg dcd8b6389b apply the new cat hack to printf, too, to prefer it over the builtin 2015-07-09 20:20:45 +00:00
tg 950827394b more easy OS/2 fixes
From: KO Myung-Hun <komh@chollian.net>
2015-07-09 19:46:43 +00:00
tg 041666eefb a few more mksh-os2 inspired fixes 2015-07-09 19:28:21 +00:00
KO Myung-Hun 65d8ad9dae Merge remote-tracking branch 'mksh/master' 2015-07-08 19:31:55 +09:00
tg f463d9da76 • revert the cat hack for realpath and rename
‣ I was convinced by several that more magic is never the solution
• fix a comment: function cat already had precedence
• change cat loader to look for existence, FPATH included, before
  ditching the builtin; note that in manpage
2015-07-06 17:48:37 +00:00
tg e0196f47d5 implement completely new multiline code by delaying history store
this commit is valgrind-tested
2015-07-05 19:37:18 +00:00
tg 62e27c3e07 simplify print_columns func argument: no need to return the first arg any more 2015-07-05 14:43:08 +00:00
tg 7a1acedd4a bump; nothing to merge from oksh, and nothing more from me today 2015-06-28 16:23:24 +00:00
KO Myung-Hun 645b537439 Support BEGINLIBPATH, ENDLIBPATH and LIBPATHSTRICT on OS/2 2015-06-03 13:00:50 +09:00
KO Myung-Hun 89324074c4 Prepend /@unixroot to rooted paths on OS/2
$UNIXROOT is a root directory of FHS on OS/2. /@unixroot is replaced by
$UNIXROOT at runtime.
2015-06-03 13:00:49 +09:00
KO Myung-Hun 07e5cadc54 Support a response file on OS/2 2015-06-03 13:00:43 +09:00
KO Myung-Hun 759b6ec59f Consider OS/2-style path
OS/2 uses 'x:' as a drive prefix and '\' as a directory separator.
2015-06-03 13:00:43 +09:00
KO Myung-Hun a03cf65602 Consider executable extensions in case of some test commands on OS/2
-r, -w, -x, -a, -e, -f.
2015-06-03 13:00:42 +09:00
KO Myung-Hun 5127457319 Read in text mode, write in binary mode on OS/2
This enables to convert CR+LF to LF when reading, but disables to
convert LF to CR+LF when writing.

Instead, however, CR+LF are not passed into mksh as is.
2015-06-03 13:00:41 +09:00
KO Myung-Hun 5ed2481df2 Try to append executable suffixes if not having extension on OS/2 2015-06-03 13:00:40 +09:00
KO Myung-Hun 8f633da789 Path separator is ; on OS/2 2015-06-03 13:00:40 +09:00
KO Myung-Hun aeeabefbe5 Do not define getrusage() stuffs on OS/2 kLIBC
OS/2 kLIBC has only a declaration of getrusage() without implementation.
Due to this, definition of getrusage() stuffs causes compilation to fail.

-----
In file included from lalloc.c:21:
sh.h:379: error: conflicting types for `getrusage'
f:/lang/gcc/usr/include/sys/resource.h:168: error: previous declaration of `getrusage'
-----
2015-06-03 13:00:39 +09:00
tg babd9c4cf0 The check for empty patterns and patterns matching the empty string
in commitid 1004D8283F068C41C3C was bogus; it fixed Jb_boin’s issue
but izabers’s 「var=foo; echo "${var/*/x}"」 was broken; in fact we
only want to not do the looping for // if the pattern matches much.

Also, fix a spelling mistake in the manpage and change some wording
to also work with associative arrays (in the future; no change).
2015-05-23 17:43:22 +00:00
tg 93ccb42114 overhaul the signal handling:
• support NSIG_MAX from http://austingroupbugs.net/view.php?id=741
  and make a TODO for later to use sysconf(_SC_NSIG) at runtime
• bounds-check signals (e.g. no smaller than 1, but smaller than NSIG)
• align trap errorlevel with other shells
• make trap match what’s in POSIX and fixup the manpage
• refactor some code related to signals
• hide from kill builtin both EXIT and ERR pseudo-signals
2015-04-29 20:44:37 +00:00
tg 609b311919 more low-hanging fruits for EBCDIC; notes:
• ord() new, From: Daniel Richard G. <skunk@iSKUNK.ORG>
  ‣ used in some places
• (c - '0') → ksh_numdig(c)	# may take *x++ argument
• (c - 'A') → ksh_numuc(c)	# may NOT take *x+= argument
  ‣ idem for ksh_numlc(c) and 'a'
  ‣ these need changing for EBCDIC
  ‣ add testsuite for this
• use macros more, they exist already often
• use digits_lc[foo] instead of ('0' + foo), especially for letters
• caught another ksh_eq case…
• also caught a maybe-UB overflow check, but we don’t have TIME_T_MAX ☹
2015-04-29 20:07:35 +00:00
tg 3eb806b72b inline only user of ksh_min, make it more cool; drop ksh_min, ksh_max;
move ksh_isdigit etc. to ksh_isalpha etc. definitions
2015-04-29 19:11:57 +00:00
tg 2cb0ea982a EBCDIC helpers and OS/390 signals 2015-04-29 18:38:54 +00:00
tg c9ccf0bab7 MFC remaining fixes; tested locally a lot, plus remotely with
GNU C11 (Debian 20150413-1) version 5.0.1 20150413 (prerelease) [gcc-5-branch revision 222050] (x86_64-linux-gnu)
including ASan (testsuite) and Valgrind (short)
2015-04-19 19:18:07 +00:00
tg 65f9b93926 ordinarily, lineno must be mksh_uari_t, but edit.c most of all isn’t ready,
so we mitigate a bit (in var.c mostly) and tweak another type already, and
add some checks (mksh_{,u}ari_t must fit into {,unsigned }long) and print
line numbers with %lu already
2015-04-19 18:50:38 +00:00
tg cad9bc86d3 Implement the “FKSH functions have local scope for shell options” feature
for mksh but not lksh; bump to R51-alpha.

While here, tweak build scripts a bit, fixup MirBSD-specific Makefile
things, remove part of a comment that’s uninteresting.
2015-04-11 23:28:21 +00:00
tg e1cda74d04 SECURITY: fix integer overflows related to file descriptor parsing
bug initially found by Pawel Wylecial (LP#1440685)
additional bug found and suggested fix by enh (elliott hughes)

This commit also renames struct ioword.flag to ioflag to disambiguate
it from other members named “flag”, changes it to an unsigned type,
and packs ioflag and unit into shorts each, to make the struct smaller
(aligned even: 16 bytes on 32-bit systems) and reviews some of the
code involved in fd handling, though there wasn’t much to be found.
2015-04-11 22:03:32 +00:00
tg 07898d8a45 only lksh now implies unalias for a POSIX function definition (used e.g. in Debian sysvinit scripts that use a “stop” function) 2015-03-20 23:37:55 +00:00
tg 2097d45f7f oksh rcsid-only sync, plus bonus rewrite of strip_nuls
(uses size_t ipv int for buffer size now, and no extra
calls to memchr/memmove, input is typically small)
2015-03-20 21:46:41 +00:00
tg 0d72355038 “local x=$1” is supposed to not field-split and so 2015-03-14 05:23:18 +00:00
tg 96d9e5d1f1 remove unused CMDWORD 2015-03-14 04:37:55 +00:00
tg 8f53c68265 • protect POSIX builtins and utilities from aliases, e.g:
‣ : → \:
  ‣ alias → \alias
    ⇒ except in some internally used cases, where we use \builtin alias
  ‣ command . → \command .
• protect Korn Shell builtins from aliases and functions, e.g:
  ‣ typeset → \builtin typeset
    ⇒ also unravels the “local” alias used
  ‣ print → \builtin print
• protect internally-used things from aliases
  ‣ “let]” is not a valid function name
  ‣ “set” is POSIX so we don’t expect anyone to override it in a function
• use “command -v” instead of “whence -p” (“which”) in most
  places; thanks izabera from #ed on IRC for pointing out
  that “command -v” is POSIX – except, “whence -p” a̲l̲w̲a̲y̲s̲ looks
  for an executable and shows its full pathname; “command -v”
  also resolves to aliases, functions and builtins, so only use
  it where it makes any sense (both never output to stderr)
• make most of dot.mkshrc work in the face of such aliases
  ‣ “ulimit -c” is used; this is not POSIX, and not portable;
    maybe we should make ulimit accept-and-ignore the most
    common limits even if the OS doesn’t use them?
• update list of builtin aliases in the manpage
2015-03-08 22:54:36 +00:00
tg fcc59eee48 remove some unused string pooling stuff 2015-03-08 21:30:22 +00:00
tg be147e3426 SECURITY: make “unset HISTFILE” really work
additionally, make “HISTFILE=” the same, document the truncation and
re-reading process’ further and already-known bugs; this needs work
2015-03-07 20:46:31 +00:00
tg 707add559f keep “set -x” disabled during PS4 expansion, to avoid infinite looping 2015-03-01 15:23:05 +00:00
tg f4ae6f7508 can't set word=IFS_QUOTE if already IFS_WORD (something there)
or IFS_QUOTE (third dquote (second OQUOTE) in """something)
2015-02-20 07:14:30 +00:00
tg 73082b9292 • fixup here document expansion (regression wrt. pdksh 5.2.14)
• adjust testsuite (and write tons of new tests) after today’s commits
2015-02-19 22:26:50 +00:00
tg 4157cca352 oksh sync; unsure if it applies (with us using old_source and all) but
better be safe than sorry; it at least passes our testsuite

NOTE: people who can figure out how afl can be used for mksh welcome! ;-)
2015-02-13 12:51:33 +00:00
tg f6f49a119b add getopts for exec (unbreaks “exec -- /bin/ls”) and steal -a and -c from ksh93 2015-02-06 10:56:49 +00:00
tg 934929c2ee rcsid sync from obsd; misc sync; small improvements
• mksh testsuite no longer uses printf, again
• use MAXPATHLEN from <sys/param.h> as PATH_MAX fallback
2015-01-25 15:23:43 +00:00
tg e49d7bc3c6 better 2015-01-04 21:08:10 +00:00
tg 51c370459e bump version and, also, year… I hate this… 2014 is gonna follow us for a while… 2015-01-02 13:21:28 +00:00
tg dcdc828c41 fix here string parsing problem found by Stéphane Chazelas 2014-12-15 22:50:11 +00:00
tg 2f52b993a1 • Build.sh: fix NSIG detection for gcc-snapshot
• all: bump version to R50-current; add more comments; whitespace
• all: remove all mkssert(); we’ll do full re-runs of scan-build and,
  hopefully, Coverity Scan/Prevent
• check.t: fix a testcase (sed could exit false, but we don’t care)
• eval.c: fix tilde_ok data type (only unsigned may shl constantly)
• exec.c: fix shebang buf array accesses to always go via uint8_t *
2014-11-25 21:13:31 +00:00
tg 517bd63fe5 rename the “tilde” function; apparently, some system headers define it 2014-11-19 21:49:12 +00:00
tg 9b31399aec fix buffer overflow found by zacts from IRC (bad length calculation)
now zsh and mksh are even… :|
2014-11-19 18:44:11 +00:00
tg 8d9d86ceab mark two ($@/$* expansion-related) testcases as expected-fail, with more to come ☹ 2014-11-14 20:21:29 +00:00
tg 44dc99cb35 first cut at LP#1381993 (probably incomplete) plus test coverage
also remove fbsd testsuite link, it’s gone during cvs→svn of theirs ☹
2014-10-19 21:53:08 +00:00