loksh-noxz

[fork] a Linux port of OpenBSD's ksh
git clone https://noxz.tech/git/loksh-noxz.git
Log | Files | README

commit: a99bdd3932b8f9f1e19ada06d6936b7d04125028
parent: 4418d329ddcd8655e63b2b4cc5cb12b173d05c92
author: Chris Noxz <chris@noxz.tech>
date:   Tue, 9 Mar 2021 19:16:04 +0100
Match upstream 6.7
Mhistory.c22+++++++++++++-------
Mksh.110+++++----
Mvar.c6+++++-
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/history.c b/history.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: history.c,v 1.82 2019/06/28 13:34:59 deraadt Exp $	*/
+/*	$OpenBSD: history.c,v 1.84 2019/10/27 15:02:19 jca Exp $	*/
 
 /*
  * command history
@@ -558,6 +558,7 @@ void
 sethistsize(int n)
 {
 	if (n > 0 && (uint32_t)n != histsize) {
+		char **tmp;
 		int offset = histptr - history;
 
 		/* save most recent history */
@@ -570,10 +571,15 @@ sethistsize(int n)
 			memmove(history, histptr - offset, n * sizeof(char *));
 		}
 
-		histsize = n;
-		histbase = areallocarray(histbase, n + 1, sizeof(char *), APERM);
-		history = histbase + 1;
-		histptr = history + offset;
+		tmp = reallocarray(histbase, n + 1, sizeof(char *));
+		if (tmp != NULL) {
+			histbase = tmp;
+			histsize = n;
+			history = histbase + 1;
+			histptr = history + offset;
+		} else
+			warningf(false, "resizing history storage: %s",
+			    strerror(errno));
 	}
 }
 
@@ -617,8 +623,10 @@ init_histvec(void)
 		 * allocate one extra element so that histptr always
 		 * lies within array bounds
 		 */
-		histbase = areallocarray(NULL, histsize + 1, sizeof(char *),
-		    APERM);
+		histbase = reallocarray(NULL, histsize + 1, sizeof(char *));
+		if (histbase == NULL)
+			internal_errorf("allocating history storage: %s",
+			    strerror(errno));
 		*histbase = NULL;
 		history = histbase + 1;
 		histptr = history - 1;
diff --git a/ksh.1 b/ksh.1
@@ -1,8 +1,8 @@
-.\"	$OpenBSD: ksh.1,v 1.207 2019/06/24 15:05:17 jca Exp $
+.\"	$OpenBSD: ksh.1,v 1.208 2019/11/26 22:49:01 jmc Exp $
 .\"
 .\"	Public Domain
 .\"
-.Dd $Mdocdate: June 24 2019 $
+.Dd $Mdocdate: November 26 2019 $
 .Dt KSH 1
 .Os
 .Sh NAME
@@ -1341,7 +1341,7 @@ Note that if
 .Ev CDPATH
 is set and does not contain
 .Sq \&.
-or contains an empty path, the current directory is not searched.
+or an empty path, the current directory is not searched.
 Also, the
 .Ic cd
 built-in command will display the resulting directory when a match is found
@@ -2866,7 +2866,9 @@ is set, it lists the search path for the directory containing
 .Ar dir .
 A
 .Dv NULL
-path means the current directory.
+path or
+.Ql .\&
+means the current directory.
 If
 .Ar dir
 is found in any component of the
diff --git a/var.c b/var.c
@@ -1,4 +1,4 @@
-/*	$OpenBSD: var.c,v 1.70 2018/06/18 21:46:05 millert Exp $	*/
+/*	$OpenBSD: var.c,v 1.71 2020/02/21 18:21:23 tb Exp $	*/
 
 #include <sys/stat.h>
 #include <sys/time.h>
@@ -1052,6 +1052,10 @@ setspec(struct tbl *vp)
 		vp->flag |= SPECIAL;
 		break;
 	case V_TMOUT:
+		/* Enforce integer to avoid command execution from initcoms[] */
+		vp->flag &= ~SPECIAL;
+		intval(vp);
+		vp->flag |= SPECIAL;
 		/* at&t ksh seems to do this (only listen if integer) */
 		if (vp->flag & INTEGER)
 			ksh_tmout = vp->val.i >= 0 ? vp->val.i : 0;