From owner-svn-src-head@freebsd.org Thu May 18 21:44:16 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5E9D3D6FC63; Thu, 18 May 2017 21:44:16 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0C1101B68; Thu, 18 May 2017 21:44:15 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4ILiF7t046858; Thu, 18 May 2017 21:44:15 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4ILiEOs046856; Thu, 18 May 2017 21:44:14 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201705182144.v4ILiEOs046856@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Thu, 18 May 2017 21:44:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318501 - head/bin/sh X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 May 2017 21:44:16 -0000 Author: jilles Date: Thu May 18 21:44:14 2017 New Revision: 318501 URL: https://svnweb.freebsd.org/changeset/base/318501 Log: sh: Ensure memout.bufsize matches allocated buffer, if it exists. Modified: head/bin/sh/eval.c head/bin/sh/output.c Modified: head/bin/sh/eval.c ============================================================================== --- head/bin/sh/eval.c Thu May 18 21:23:39 2017 (r318500) +++ head/bin/sh/eval.c Thu May 18 21:44:14 2017 (r318501) @@ -1081,8 +1081,6 @@ evalcommand(union node *cmd, int flags, mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH; if (flags == EV_BACKCMD) { memout.nextc = memout.buf; - memout.bufend = memout.buf; - memout.bufsize = 64; mode |= REDIR_BACKQ; } savecmdname = commandname; @@ -1139,6 +1137,7 @@ cmddone: memout.buf = NULL; memout.nextc = NULL; memout.bufend = NULL; + memout.bufsize = 64; } if (cmdentry.u.index != EXECCMD) popredir(); Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Thu May 18 21:23:39 2017 (r318500) +++ head/bin/sh/output.c Thu May 18 21:44:14 2017 (r318501) @@ -73,7 +73,7 @@ static int doformat_wr(void *, const cha struct output output = {NULL, NULL, NULL, OUTBUFSIZ, 1, 0}; struct output errout = {NULL, NULL, NULL, 256, 2, 0}; -struct output memout = {NULL, NULL, NULL, 0, MEM_OUT, 0}; +struct output memout = {NULL, NULL, NULL, 64, MEM_OUT, 0}; struct output *out1 = &output; struct output *out2 = &errout; @@ -208,7 +208,7 @@ outbin(const void *data, size_t len, str void emptyoutbuf(struct output *dest) { - int offset; + int offset, newsize; if (dest->buf == NULL) { INTOFF; @@ -218,10 +218,11 @@ emptyoutbuf(struct output *dest) INTON; } else if (dest->fd == MEM_OUT) { offset = dest->nextc - dest->buf; + newsize = dest->bufsize << 1; INTOFF; - dest->bufsize <<= 1; - dest->buf = ckrealloc(dest->buf, dest->bufsize); - dest->bufend = dest->buf + dest->bufsize; + dest->buf = ckrealloc(dest->buf, newsize); + dest->bufsize = newsize; + dest->bufend = dest->buf + newsize; dest->nextc = dest->buf + offset; INTON; } else {