From patchwork Thu Jul 18 15:30:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Shadura X-Patchwork-Id: 11049235 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABFAD13A4 for ; Thu, 18 Jul 2019 15:31:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CFB4286D0 for ; Thu, 18 Jul 2019 15:31:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91914287FA; Thu, 18 Jul 2019 15:31:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E71F286D0 for ; Thu, 18 Jul 2019 15:31:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbfGRPbi (ORCPT ); Thu, 18 Jul 2019 11:31:38 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:56212 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726040AbfGRPbi (ORCPT ); Thu, 18 Jul 2019 11:31:38 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrewsh) with ESMTPSA id 6ADB728BF99 From: Andrej Shadura To: dash@vger.kernel.org Cc: Chris Lamb Subject: [PATCH] dash: Fix stack overflow from infinite recursion in script Date: Thu, 18 Jul 2019 12:30:28 -0300 Message-Id: <20190718153028.18791-1-andrew.shadura@collabora.co.uk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Chris Lamb Bug-Debian: https://bugs.debian.org/579815 Signed-off-by: Chris Lamb Signed-off-by: Andrej Shadura --- src/eval.c | 8 +++++++- src/eval.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/eval.c b/src/eval.c index 1aad31a..ee36c39 100644 --- a/src/eval.c +++ b/src/eval.c @@ -69,6 +69,7 @@ int evalskip; /* set if we are skipping commands */ STATIC int skipcount; /* number of levels to skip */ MKINIT int loopnest; /* current loop nesting level */ static int funcline; /* starting line number of current function, or 0 if not in a function */ +static int evalcount; /* number of nested evalfun calls */ char *commandname; @@ -903,7 +904,12 @@ raise: break; case CMDFUNCTION: - if (evalfun(cmdentry.u.func, argc, argv, flags)) + if (evalcount++ >= MAX_RECURSION) + sh_error("Maximum function recursion depth (%d) reached", + MAX_RECURSION); + int i = evalfun(cmdentry.u.func, argc, argv, flags); + evalcount--; + if (i) goto raise; break; } diff --git a/src/eval.h b/src/eval.h index 63e7d86..38dffbd 100644 --- a/src/eval.h +++ b/src/eval.h @@ -51,6 +51,8 @@ struct backcmd { /* result of evalbackcmd */ #define EV_EXIT 01 /* exit after evaluating tree */ #define EV_TESTED 02 /* exit status is checked; ignore -e flag */ +#define MAX_RECURSION 1000 /* maximum recursion level */ + int evalstring(char *, int); union node; /* BLETCH for ansi C */ int evaltree(union node *, int);