From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:41835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRwRg-0006w0-HV for qemu-devel@nongnu.org; Wed, 01 Jun 2011 21:11:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QRp2w-0007p7-Pz for qemu-devel@nongnu.org; Wed, 01 Jun 2011 13:21:15 -0400 Received: from mout.perfora.net ([74.208.4.195]:57612) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRp2w-0007ob-B0 for qemu-devel@nongnu.org; Wed, 01 Jun 2011 13:17:30 -0400 From: Michael Roth Date: Wed, 1 Jun 2011 12:14:52 -0500 Message-Id: <1306948500-15086-7-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1306948500-15086-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1306948500-15086-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v1][ 06/14] json-lexer: limit the maximum size of a given token List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com From: Anthony Liguori Signed-off-by: Michael Roth --- json-lexer.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/json-lexer.c b/json-lexer.c index 65c9720..fe5a060 100644 --- a/json-lexer.c +++ b/json-lexer.c @@ -18,6 +18,8 @@ #include "qemu-common.h" #include "json-lexer.h" +#define MAX_TOKEN_SIZE (64ULL << 20) + /* * \"([^\\\"]|(\\\"\\'\\\\\\/\\b\\f\\n\\r\\t\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]))*\" * '([^\\']|(\\\"\\'\\\\\\/\\b\\f\\n\\r\\t\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]))*' @@ -309,6 +311,17 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch) } lexer->state = new_state; } while (!char_consumed); + + /* Do not let a single token grow to an arbitrarily large size, + * this is a security consideration. + */ + if (lexer->token->length > MAX_TOKEN_SIZE) { + lexer->emit(lexer, lexer->token, lexer->state, lexer->x, lexer->y); + QDECREF(lexer->token); + lexer->token = qstring_new(); + lexer->state = IN_START; + } + return 0; } -- 1.7.0.4