From owner-svn-src-all@FreeBSD.ORG Sat Dec 11 17:47:28 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 32250106564A; Sat, 11 Dec 2010 17:47:28 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 212278FC12; Sat, 11 Dec 2010 17:47:28 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBBHlSfa013724; Sat, 11 Dec 2010 17:47:28 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBBHlSJw013722; Sat, 11 Dec 2010 17:47:28 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201012111747.oBBHlSJw013722@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 11 Dec 2010 17:47:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216380 - head/bin/sh X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Dec 2010 17:47:28 -0000 Author: jilles Date: Sat Dec 11 17:47:27 2010 New Revision: 216380 URL: http://svn.freebsd.org/changeset/base/216380 Log: sh: Use vsnprintf() rather than crafting our own in fmtstr(). Add INTOFF/INTON as longjmp out of vsnprintf may cause memory leaks or undefined behaviour. Modified: head/bin/sh/output.c Modified: head/bin/sh/output.c ============================================================================== --- head/bin/sh/output.c Sat Dec 11 16:06:52 2010 (r216379) +++ head/bin/sh/output.c Sat Dec 11 17:47:27 2010 (r216380) @@ -64,8 +64,7 @@ __FBSDID("$FreeBSD$"); #define OUTBUFSIZ BUFSIZ -#define BLOCK_OUT -2 /* output to a fixed block of memory */ -#define MEM_OUT -3 /* output to dynamically allocated memory */ +#define MEM_OUT -2 /* output to dynamically allocated memory */ #define OUTPUT_ERR 01 /* error occurred on output */ static int doformat_wr(void *, const char *, int); @@ -180,18 +179,12 @@ outbin(const void *data, size_t len, str outc(*p++, file); } -static char out_junk[16]; - void emptyoutbuf(struct output *dest) { int offset; - if (dest->fd == BLOCK_OUT) { - dest->nextc = out_junk; - dest->nleft = sizeof out_junk; - dest->flags |= OUTPUT_ERR; - } else if (dest->buf == NULL) { + if (dest->buf == NULL) { INTOFF; dest->buf = ckmalloc(dest->bufsize); dest->nextc = dest->buf; @@ -282,18 +275,12 @@ void fmtstr(char *outbuf, int length, const char *fmt, ...) { va_list ap; - struct output strout; - strout.nextc = outbuf; - strout.nleft = length; - strout.fd = BLOCK_OUT; - strout.flags = 0; + INTOFF; va_start(ap, fmt); - doformat(&strout, fmt, ap); + vsnprintf(outbuf, length, fmt, ap); va_end(ap); - outc('\0', &strout); - if (strout.flags & OUTPUT_ERR) - outbuf[length - 1] = '\0'; + INTON; } static int