From efe1b9dcc5443fd1c618a5282597185c29496694 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Mon, 6 Sep 2021 12:35:57 +0200 Subject: [PATCH] Modifiers no longer breaks history --- .tcsh.metadata | 1 + ...dont-corrupt-history-using-modifiers.patch | 70 +++++++++++++++++++ tcsh-6.22.03-expose-HIST_PURGE.patch | 62 ++++++++++++++++ tcsh.spec | 8 ++- 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 .tcsh.metadata create mode 100644 tcsh-6.22.03-dont-corrupt-history-using-modifiers.patch create mode 100644 tcsh-6.22.03-expose-HIST_PURGE.patch diff --git a/.tcsh.metadata b/.tcsh.metadata new file mode 100644 index 0000000..9160605 --- /dev/null +++ b/.tcsh.metadata @@ -0,0 +1 @@ +3d1e4a0087a41350ce81fb1a9a04403c5ffb7e5f tcsh-6.22.03.tar.gz diff --git a/tcsh-6.22.03-dont-corrupt-history-using-modifiers.patch b/tcsh-6.22.03-dont-corrupt-history-using-modifiers.patch new file mode 100644 index 0000000..3820a46 --- /dev/null +++ b/tcsh-6.22.03-dont-corrupt-history-using-modifiers.patch @@ -0,0 +1,70 @@ +From 04a68ad191cfcb87cdff70a6b913721e423cd28b Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 23 Aug 2021 08:31:59 -0400 +Subject: [PATCH] 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 + +--- + 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 e230becd..1ac9716e 100644 +--- a/sh.decls.h ++++ b/sh.decls.h +@@ -217,6 +217,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 14d862a3..40660bdc 100644 +--- a/sh.hist.c ++++ b/sh.hist.c +@@ -1184,6 +1184,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 9f2b1a29..df4aa7a3 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); + } diff --git a/tcsh-6.22.03-expose-HIST_PURGE.patch b/tcsh-6.22.03-expose-HIST_PURGE.patch new file mode 100644 index 0000000..df2e554 --- /dev/null +++ b/tcsh-6.22.03-expose-HIST_PURGE.patch @@ -0,0 +1,62 @@ +From c14852867786c798f98a23d075e76a2e2acce204 Mon Sep 17 00:00:00 2001 +From: Christos Zoulas +Date: Mon, 23 Aug 2021 08:30:57 -0400 +Subject: [PATCH] - Expose HIST_PURGE - Compare pointer against null - Use + initlex() + +--- + sh.h | 2 ++ + sh.lex.c | 6 ++---- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/sh.h b/sh.h +index 3c285a9e..77e801c6 100644 +--- a/sh.h ++++ b/sh.h +@@ -78,6 +78,7 @@ typedef unsigned long intptr_t; + #if defined(KANJI) && defined(WIDE_STRINGS) && defined(HAVE_NL_LANGINFO) && defined(CODESET) + #define AUTOSET_KANJI + #endif ++ + /* + * Sanity + */ +@@ -1027,6 +1028,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 5b0c6d8d..afe053e5 100644 +--- a/sh.lex.c ++++ b/sh.lex.c +@@ -153,8 +153,7 @@ lex(struct wordent *hp) + + if (!postcmd_active) + btell(&lineloc); +- hp->next = hp->prev = hp; +- hp->word = STRNULL; ++ initlex(hp); + hadhist = 0; + do + c = readc(0); +@@ -711,7 +710,7 @@ getexcl(Char sc) + + lastev = eventno; + hp = gethent(sc); +- if (hp == 0) ++ if (hp == NULL) + return; + hadhist = 1; + dol = 0; +@@ -901,7 +900,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) + { diff --git a/tcsh.spec b/tcsh.spec index b1c252c..1d3d9bd 100644 --- a/tcsh.spec +++ b/tcsh.spec @@ -13,7 +13,7 @@ Name: tcsh Summary: An enhanced version of csh, the C shell Version: 6.22.03 -Release: 5%{?dist} +Release: 6%{?dist} License: BSD URL: http://www.tcsh.org/ @@ -44,6 +44,9 @@ BuildRequires: ncurses-devel # Upstream patches -- official upstream patches released by upstream since the # ---------------- last rebase that are necessary for any reason: +Patch001: tcsh-6.22.03-expose-HIST_PURGE.patch +Patch002: tcsh-6.22.03-dont-corrupt-history-using-modifiers.patch + # Downstream patches -- these should be always included when doing rebase: # ------------------ @@ -177,6 +180,9 @@ fi # ============================================================================= %changelog +* Mon Sep 06 2021 Jan Macku - 6.22.03-6 +- Modifiers no longer breaks history - rhbz#1997986 + * Tue Aug 10 2021 Mohan Boddu - 6.22.03-5 - Rebuilt for IMA sigs, glibc 2.34, aarch64 flags Related: rhbz#1991688