Compare commits

...

No commits in common. "imports/c8-beta/tcsh-6.20.00-9.el8" and "c8" have entirely different histories.

9 changed files with 488 additions and 2 deletions

View File

@ -0,0 +1,137 @@
diff --git a/Fixes b/Fixes
--- a/Fixes
+++ b/Fixes
@@ -2,7 +2,6 @@
4. Don't play pointer tricks that are undefined in modern c (Brooks Davis)
3. Fix out of bounds read (Brooks Davis)
2. Fix type of read in prompt confirmation (eg. rmstar) (David Kaspar)
- 1. PR/471: Delay arginp parsing
20. V6.20.00 - 20161124
19. Don't resize the screen if it did not change size.
diff --git a/sh.c b/sh.c
--- a/sh.c
+++ b/sh.c
@@ -249,7 +249,6 @@ main(int argc, char **argv)
char *tcp, *ttyn;
int f, reenter;
char **tempv;
- const char *targinp = NULL;
int osetintr;
struct sigaction oparintr;
@@ -941,7 +940,30 @@ main(int argc, char **argv)
*p &= ASCII;
}
#endif
- targinp = tempv[0];
+ arginp = SAVE(tempv[0]);
+
+ /*
+ * we put the command into a variable
+ */
+ if (arginp != NULL)
+ setv(STRcommand, quote(Strsave(arginp)), VAR_READWRITE);
+
+ /*
+ * * Give an error on -c arguments that end in * backslash to
+ * ensure that you don't make * nonportable csh scripts.
+ */
+ {
+ int count;
+
+ cp = Strend(arginp);
+ count = 0;
+ while (cp > arginp && *--cp == '\\')
+ ++count;
+ if ((count & 1) != 0) {
+ exiterr = 1;
+ stderror(ERR_ARGC);
+ }
+ }
prompt = 0;
nofile = 1;
break;
@@ -1186,7 +1208,7 @@ main(int argc, char **argv)
sigset_interrupting(SIGXFSZ, queue_phup);
#endif
- if (quitit == 0 && targinp == 0) {
+ if (quitit == 0 && arginp == 0) {
#ifdef SIGTSTP
(void) signal(SIGTSTP, SIG_IGN);
#endif
@@ -1304,7 +1326,7 @@ main(int argc, char **argv)
*/
sigset_interrupting(SIGCHLD, queue_pchild);
- if (intty && !targinp)
+ if (intty && !arginp)
(void) ed_Setup(editing);/* Get the tty state, and set defaults */
/* Only alter the tty state if editing */
@@ -1339,7 +1361,7 @@ main(int argc, char **argv)
#ifdef _PATH_DOTCSHRC
(void) srcfile(_PATH_DOTCSHRC, 0, 0, NULL);
#endif
- if (!targinp && !onelflg && !havhash)
+ if (!arginp && !onelflg && !havhash)
dohash(NULL,NULL);
#ifndef LOGINFIRST
#ifdef _PATH_DOTLOGIN
@@ -1359,7 +1381,7 @@ main(int argc, char **argv)
if (!srccat(varval(STRhome), STRsldottcshrc))
(void) srccat(varval(STRhome), STRsldotcshrc);
- if (!targinp && !onelflg && !havhash)
+ if (!arginp && !onelflg && !havhash)
dohash(NULL,NULL);
/*
@@ -1379,7 +1401,7 @@ main(int argc, char **argv)
exitset--;
/* Initing AFTER .cshrc is the Right Way */
- if (intty && !targinp) { /* PWP setup stuff */
+ if (intty && !arginp) { /* PWP setup stuff */
ed_Init(); /* init the new line editor */
#ifdef SIG_WINDOW
check_window_size(1); /* mung environment */
@@ -1395,37 +1417,6 @@ main(int argc, char **argv)
setNS(STRecho);
- if (targinp) {
- /* If this -c command caused an error before, skip processing */
- if (reenter && arginp) {
- exitcode = 1;
- goto done;
- }
-
- arginp = SAVE(targinp);
- /*
- * we put the command into a variable
- */
- if (arginp != NULL)
- setv(STRcommand, quote(Strsave(arginp)), VAR_READWRITE);
-
- /*
- * * Give an error on -c arguments that end in * backslash to
- * ensure that you don't make * nonportable csh scripts.
- */
- {
- int count;
-
- cp = Strend(arginp);
- count = 0;
- while (cp > arginp && *--cp == '\\')
- ++count;
- if ((count & 1) != 0) {
- exiterr = 1;
- stderror(ERR_ARGC);
- }
- }
- }
/*
* All the rest of the world is inside this call. The argument to process
* indicates whether it should catch "error unwinds". Thus if we are a

View File

@ -0,0 +1,48 @@
From 1ef6e9d0eef9278829f863fff55755b7a5415b81 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Fri, 11 Jan 2019 10:49:54 -0500
Subject: [PATCH] Abort history loading on long lines
diff --git a/sh.lex.c b/sh.lex.c
index fee790a..e945795 100644
--- a/sh.lex.c
+++ b/sh.lex.c
@@ -145,6 +145,7 @@ lex(struct wordent *hp)
struct wordent *wdp;
eChar c;
int parsehtime = enterhist;
+ int toolong = 0;
histvalid = 0;
histline.len = 0;
@@ -179,6 +180,8 @@ lex(struct wordent *hp)
wdp = new;
wdp->word = word(parsehtime);
parsehtime = 0;
+ if (enterhist && toolong++ > 10 * 1024)
+ stderror(ERR_LTOOLONG);
} while (wdp->word[0] != '\n');
cleanup_ignore(hp);
cleanup_until(hp);
@@ -291,9 +294,12 @@ word(int parsehtime)
Char hbuf[12];
int h;
int dolflg;
+ int toolong = 0;
cleanup_push(&wbuf, Strbuf_cleanup);
loop:
+ if (enterhist && toolong++ > 256 * 1024)
+ seterror(ERR_WTOOLONG);
while ((c = getC(DOALL)) == ' ' || c == '\t')
continue;
if (cmap(c, _META | _ESC))
@@ -352,6 +358,8 @@ word(int parsehtime)
c1 = 0;
dolflg = DOALL;
for (;;) {
+ if (enterhist && toolong++ > 256 * 1024)
+ seterror(ERR_WTOOLONG);
if (c1) {
if (c == c1) {
c1 = 0;

View File

@ -0,0 +1,47 @@
From 83c5be028419b3f27c3cc707b88fb21bfa4e1b11 Mon Sep 17 00:00:00 2001
From: zoulasc <christos@zoulas.com>
Date: Sat, 19 Oct 2019 08:52:53 -0400
Subject: [PATCH] FIx PR/113: failing -c command causes infinite loop
diff --git a/sh.c b/sh.c
index 4b5c624..dd87172 100644
--- a/sh.c
+++ b/sh.c
@@ -237,6 +237,7 @@ main(int argc, char **argv)
int nofile = 0;
volatile int nverbose = 0;
volatile int rdirs = 0;
+ volatile int exitcode = 0;
int quitit = 0;
Char *cp;
#ifdef AUTOLOGOUT
@@ -1390,6 +1391,12 @@ main(int argc, char **argv)
if (targinp) {
+ /* If this -c command caused an error before, skip processing */
+ if (reenter && arginp) {
+ exitcode = 1;
+ goto done;
+ }
+
arginp = SAVE(targinp);
/*
* we put the command into a variable
@@ -1422,6 +1429,7 @@ main(int argc, char **argv)
*/
process(setintr);
+done:
/*
* Mop-up.
*/
@@ -1443,7 +1451,7 @@ main(int argc, char **argv)
}
record();
exitstat();
- return (0);
+ return exitcode;
}
void

View File

@ -0,0 +1,25 @@
From 4723e1754cd28657183358334fe77fe328f01bd0 Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos.zoulas@twosigma.com>
Date: Fri, 18 Oct 2019 13:35:49 -0400
Subject: [PATCH] When the load of history caused an error, say so.
diff --git a/sh.err.c b/sh.err.c
index c676f5e..010b23c 100644
--- a/sh.err.c
+++ b/sh.err.c
@@ -43,6 +43,7 @@
#endif
char *seterr = NULL; /* Holds last error if there was one */
+extern int enterhist;
#define ERR_FLAGS 0xf0000000
#define ERR_NAME 0x10000000
@@ -630,6 +631,8 @@ stderror(unsigned int id, ...)
*/
flush();/*FIXRESET*/
haderr = 1; /* Now to diagnostic output */
+ if (enterhist)
+ xprintf("Can't load history: ");/*FIXRESET*/
if (flags & ERR_NAME)
xprintf("%s: ", bname);/*FIXRESET*/
if ((flags & ERR_OLD)) {

View File

@ -0,0 +1,31 @@
From 67db04d8d8ada0aa2fb7dfdf83f3a408ad5a01dc Mon Sep 17 00:00:00 2001
From: zoulasc <christos@zoulas.com>
Date: Mon, 20 Jan 2020 11:29:01 -0500
Subject: [PATCH] Prevent phup() and record() from being executed more than
once because writing history recursively deadlocks (Brett Frankenberger)
diff --git a/sh.c b/sh.c
index dd87172..75ba62d 100644
--- a/sh.c
+++ b/sh.c
@@ -1839,6 +1839,10 @@ exitstat(void)
void
phup(void)
{
+ static int again = 0;
+ if (again++)
+ return;
+
if (loginsh) {
setcopy(STRlogout, STRhangup, VAR_READWRITE);
#ifdef _PATH_DOTLOGOUT
@@ -2516,6 +2520,10 @@ defaultpath(void)
static void
record(void)
{
+ static int again = 0;
+ if (again++)
+ return;
+
if (!fast) {
recdirs(NULL, adrof(STRsavedirs) != NULL);
rechist(NULL, adrof(STRsavehist) != NULL);

View File

@ -0,0 +1,35 @@
From 38ffe6da549152a0c411407f5846d0b8896bc25c Mon Sep 17 00:00:00 2001
From: Jan Macku <jamacku@redhat.com>
Date: Thu, 30 Jul 2020 09:42:39 +0200
Subject: [PATCH] Call stderror consistently and avoid inf loops
Suggested by Kamil Dudka
---
sh.lex.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sh.lex.c b/sh.lex.c
index a10436c..fcaae97 100644
--- a/sh.lex.c
+++ b/sh.lex.c
@@ -304,7 +304,7 @@ word(int parsehtime)
cleanup_push(&wbuf, Strbuf_cleanup);
loop:
if (enterhist && toolong++ > 256 * 1024)
- seterror(ERR_WTOOLONG);
+ stderror(ERR_WTOOLONG);
while ((c = getC(DOALL)) == ' ' || c == '\t')
continue;
if (cmap(c, _META | _ESC))
@@ -364,7 +364,7 @@ loop:
dolflg = DOALL;
for (;;) {
if (enterhist && toolong++ > 256 * 1024)
- seterror(ERR_WTOOLONG);
+ stderror(ERR_WTOOLONG);
if (c1) {
if (c == c1) {
c1 = 0;
--
2.25.4

View File

@ -0,0 +1,77 @@
From cab544f34758f71ab3070f343efb6daee68daf81 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Wed, 8 Sep 2021 11:00:35 +0200
Subject: [PATCH] Modifiers no longer breaks history
Fix bug reported by Jan Macku: alias postcmd '/bin/echo
-n "COMMAND:"'"'"'\!#:-$:gx'"'"'' echo 1 2 3 4 5
^P prints echo 1 2 3 4
Reason: domod() enters junk history entries with event number
HIST_PURGE aliasrun which is used to run postcmd modifies the history
appending those entries. Fix by explicitly cleaning up those entries in
aliasrun
Based on upstream patch: 04a68ad191cfcb87cdff70a6b913721e423cd28b from Christos Zoulas <christos@zoulas.com>
---
sh.decls.h | 1 +
sh.hist.c | 11 +++++++++++
tc.func.c | 2 ++
3 files changed, 14 insertions(+)
diff --git a/sh.decls.h b/sh.decls.h
index 8dc22d5..a75563b 100644
--- a/sh.decls.h
+++ b/sh.decls.h
@@ -218,6 +218,7 @@ extern int t_pmatch (const Char *, const Char *,
*/
extern void dohist (Char **, struct command *);
extern struct Hist *enthist (int, struct wordent *, int, int, int);
+extern void cleanhist (void);
extern void savehist (struct wordent *, int);
extern char *fmthist (int, ptr_t);
extern void rechist (Char *, int);
diff --git a/sh.hist.c b/sh.hist.c
index 1abd522..bafc711 100644
--- a/sh.hist.c
+++ b/sh.hist.c
@@ -1178,6 +1178,17 @@ dohist(Char **vp, struct command *c)
}
}
+void
+cleanhist(void)
+{
+ struct Hist *hp, *np;
+
+ for (hp = &Histlist; (np = hp->Hnext) != NULL;) {
+ if (np->Hnum != HIST_PURGE)
+ return;
+ hremove(np), hfree(np);
+ }
+}
char *
fmthist(int fmt, ptr_t ptr)
diff --git a/tc.func.c b/tc.func.c
index feb1c89..4849b55 100644
--- a/tc.func.c
+++ b/tc.func.c
@@ -999,6 +999,7 @@ aliasrun(int cnt, Char *s1, Char *s2)
getexit(osetexit);
if (seterr) {
+ cleanhist();
xfree(seterr);
seterr = NULL; /* don't repeatedly print err msg. */
}
@@ -1075,6 +1076,7 @@ aliasrun(int cnt, Char *s1, Char *s2)
}
cleanup_until(&w);
pendjob();
+ cleanhist();
/* Restore status */
setv(STRstatus, putn((tcsh_number_t)status), VAR_READWRITE);
}
--
2.31.1

View File

@ -0,0 +1,58 @@
From 534e2628b598b38801759535f38c228793253345 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Wed, 8 Sep 2021 10:52:43 +0200
Subject: [PATCH] Expose HIST_PURGE - Compare pointer against null - Use
initlex()
Based on upstream patch c14852867786c798f98a23d075e76a2e2acce204 from Christos Zoulas <christos@zoulas.com>
---
sh.h | 1 +
sh.lex.c | 6 ++----
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/sh.h b/sh.h
index a41e2e0..5f9cb14 100644
--- a/sh.h
+++ b/sh.h
@@ -1019,6 +1019,7 @@ EXTERN struct varent {
* The following are for interfacing redo substitution in
* aliases to the lexical routines.
*/
+#define HIST_PURGE -500000
EXTERN struct wordent *alhistp IZERO_STRUCT;/* Argument list (first) */
EXTERN struct wordent *alhistt IZERO_STRUCT;/* Node after last in arg list */
EXTERN Char **alvec IZERO_STRUCT,
diff --git a/sh.lex.c b/sh.lex.c
index b754fd3..065c78b 100644
--- a/sh.lex.c
+++ b/sh.lex.c
@@ -155,8 +155,7 @@ lex(struct wordent *hp)
histline.len = 0;
btell(&lineloc);
- hp->next = hp->prev = hp;
- hp->word = STRNULL;
+ initlex(hp);
hadhist = 0;
do
c = readc(0);
@@ -703,7 +702,7 @@ getexcl(Char sc)
lastev = eventno;
hp = gethent(sc);
- if (hp == 0)
+ if (hp == NULL)
return;
hadhist = 1;
dol = 0;
@@ -893,7 +892,6 @@ getsub(struct wordent *en)
* We raise the limit to 50000000
*/
-#define HIST_PURGE -50000000
static struct wordent *
dosub(Char sc, struct wordent *en, int global)
{
--
2.31.1

View File

@ -13,7 +13,7 @@
Name: tcsh
Summary: An enhanced version of csh, the C shell
Version: 6.20.00
Release: 9%{?dist}
Release: 15%{?dist}
License: BSD
URL: http://www.tcsh.org/
@ -52,12 +52,21 @@ Patch006: tcsh-6.20.00-006-cleanup-in-readme-files.patch
Patch007: tcsh-6.20.00-007-look-for-tgetent-in-libtinfo.patch
Patch008: tcsh-6.20.00-008-guard-ascii-only-reversion.patch
Patch009: tcsh-6.20.00-009-fix-regexp-for-backlash-quoting-tests.patch
Patch010: tcsh-6.20.00-010-fix-memory-consumption-while-loading-corrupted-history.patch
Patch011: tcsh-6.20.00-011-fix-infinite-loop-after-ctrlC.patch
Patch012: tcsh-6.20.00-012-warrning-history-loading.patch
Patch013: tcsh-6.20.00-013-prevent-phup-and-record-from-multiple-execution.patch
Patch014: tcsh-6.20.00-014-call-stderror-consistently-and-avoid-inf-loops.patch
Patch015: tcsh-6.20.00-expose-HIST_PURGE.patch
Patch016: tcsh-6.20.00-dont-corrupt-history-using-modifiers.patch
# Downstream patches -- these should be always included when doing rebase:
# ------------------
Patch100: tcsh-6.20.00-manpage-memoryuse.patch
# This reverts patch001: tcsh-6.20.00-001-delay-arginp-interpreting.patch
# bug 1845684
Patch101: tcsh-6.20.00-001-delay-arginp-interpreting-revert.patch
# Downstream patches for RHEL -- patches that we keep only in RHEL for various
# --------------------------- reasons, but are not enabled in Fedora:
@ -186,6 +195,25 @@ fi
# =============================================================================
%changelog
* Mon Oct 18 2021 Siteshwar Vashisht <svashisht@redhat.com> - 6.20.00-15
- Fix regression caused by bacported patch, command var is now set as before
Resolves: #1845684
* Wed Sep 08 2021 Jan Macku <jamacku@redhat.com> - 6.20.00-14
- Modifiers no longer breaks history - (#1997981)
* Mon Nov 16 2020 Jan Macku <jamacku@redhat.com> - 6.20.00-13
- fix regression caused by corrupted history (#1818766)
* Fri Nov 01 2019 Jan Macku <jamacku@redhat.com> - 6.20.00-12
- rebuilt
* Fri Nov 01 2019 Jan Macku <jamacku@redhat.com> - 6.20.00-11
- rebuilt
* Thu Oct 31 2019 Jan Macku <jamacku@redhat.com> - 6.20.00-10
- fix for rapid memory consumption caused by corrupted history (#1765649)
* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 6.20.00-9
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild