tcsh/tcsh-6.22.02-call-seterror-consistently-and-abort-quickly.patch
Jan Macku 52814d3666 Switch to stderror() when parsing history so that we stop processing immediately
Loading corrupted history should no more resulted in resource
 consumption
2020-10-14 12:46:03 +02:00

54 lines
1.3 KiB
Diff

From 064853aa25f498aa7bc4554393a53240696813fa Mon Sep 17 00:00:00 2001
From: Christos Zoulas <christos@zoulas.com>
Date: Fri, 24 Jul 2020 13:49:21 -0400
Subject: [PATCH] Call seterror consistently and abort quickly (Jan Macku)
---
sh.lex.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/sh.lex.c b/sh.lex.c
index d7d0ac5..ecab059 100644
--- a/sh.lex.c
+++ b/sh.lex.c
@@ -182,8 +182,10 @@ lex(struct wordent *hp)
wdp = new;
wdp->word = word(parsehtime);
parsehtime = 0;
- if (enterhist && toolong++ > 10 * 1024)
- stderror(ERR_LTOOLONG);
+ if (enterhist && toolong++ > 10 * 1024) {
+ seterror(ERR_LTOOLONG);
+ break;
+ }
} while (wdp->word[0] != '\n');
cleanup_ignore(hp);
cleanup_until(hp);
@@ -300,8 +302,10 @@ word(int parsehtime)
cleanup_push(&wbuf, Strbuf_cleanup);
loop:
- if (enterhist && toolong++ > 256 * 1024)
+ if (enterhist && toolong++ > 256 * 1024) {
seterror(ERR_WTOOLONG);
+ goto ret;
+ }
while ((c = getC(DOALL)) == ' ' || c == '\t')
continue;
if (cmap(c, _META | _ESC))
@@ -360,8 +364,10 @@ loop:
c1 = 0;
dolflg = DOALL;
for (;;) {
- if (enterhist && toolong++ > 256 * 1024)
+ if (enterhist && toolong++ > 256 * 1024) {
seterror(ERR_WTOOLONG);
+ goto ret;
+ }
if (c1) {
if (c == c1) {
c1 = 0;
--
2.25.4