From patchwork Sun Nov 11 10:38:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ron Yorston X-Patchwork-Id: 10677579 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 13D1C14DB for ; Sun, 11 Nov 2018 10:49:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E826D2AB8E for ; Sun, 11 Nov 2018 10:49:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB2442AB9A; Sun, 11 Nov 2018 10:49:55 +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 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 AA66D2AB8E for ; Sun, 11 Nov 2018 10:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727386AbeKKUiG (ORCPT ); Sun, 11 Nov 2018 15:38:06 -0500 Received: from balrog.mythic-beasts.com ([46.235.227.24]:39589 "EHLO balrog.mythic-beasts.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727344AbeKKUiG (ORCPT ); Sun, 11 Nov 2018 15:38:06 -0500 X-Greylist: delayed 682 seconds by postgrey-1.27 at vger.kernel.org; Sun, 11 Nov 2018 15:38:05 EST Received: from [2a00:1098:0:86:1000:33:578d:14fa] (port=37246 helo=frippery.frippery.org) by balrog.mythic-beasts.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gLn8R-0001wf-5f; Sun, 11 Nov 2018 10:38:31 +0000 Received: by frippery.frippery.org (Postfix, from userid 1000) id E4DE51FC43; Sun, 11 Nov 2018 10:38:29 +0000 (GMT) Date: Sun, 11 Nov 2018 10:38:29 +0000 From: Ron Yorston To: dash@vger.kernel.org Subject: [PATCH] parser: preserve characters on heap in backquote parsing Message-ID: <5be806a5.4FBQv2BWNLonvLir%rmy@frippery.org> User-Agent: Heirloom mailx 12.4 7/29/08 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 This bug report for BusyBox ash also applies to dash: https://bugs.busybox.net/show_bug.cgi?id=9246 With an 8MB stack the test case results in a segfault. Instead of using alloca() to preserve characters keep them on the memalloc stack. With this change the test case returns: $ dash test_case test_case: 3141: test_case: Syntax error: Unterminated quoted string If the heap is reduced to the same size as the stack, 8MB: $ ulimit -S -d 8192 $ dash test_case test_case: 0: test_case: Out of space Signed-off-by: Ron Yorston --- src/parser.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/parser.c b/src/parser.c index c4e6378..6efa8e2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1373,8 +1373,7 @@ parsebackq: { str = NULL; savelen = out - (char *)stackblock(); if (savelen > 0) { - str = alloca(savelen); - memcpy(str, stackblock(), savelen); + str = grabstackstr(out); } if (oldstyle) { /* We must read until the closing backquote, giving special