From patchwork Wed Jun 1 17:14:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 98322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B8ECB6F8E for ; Thu, 2 Jun 2011 12:16:13 +1000 (EST) Received: from localhost ([::1]:42742 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QRxSE-0005Ll-2Y for incoming@patchwork.ozlabs.org; Wed, 01 Jun 2011 22:16:10 -0400 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 Received: from localhost.localdomain ([32.97.110.59]) by mrelay.perfora.net (node=mrus4) with ESMTP (Nemesis) id 0M1WUr-1Pda0Z0Nh3-00tUP2; Wed, 01 Jun 2011 13:17:29 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 1 Jun 2011 12:14:52 -0500 Message-Id: <1306948500-15086-7-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.4 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> X-Provags-ID: V02:K0:fcsZSLpvKL+9QckwsM2PYvR2Rji4Ys38c4xYRLKgBwV RjWtZbyjJtnfJCo6PBqIfCtHFC52s11NhD+8JfoYlweSj+dArt dnaFvCR+EvP3Zde78mZ5fpKQM4jUlIVAFJGHVNX4VWYM1jDEbq 3OqNDVtP+jE+AjoDj/pI7uEcTUj6wS6Fu6nXudhY/ZXsorlGfa KSdmfdvobeMAU0YnnDTEO7nqXaTjt+L4WSvqvaNT8I= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.195 Cc: aliguori@linux.vnet.ibm.com, Jes.Sorensen@redhat.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v1][ 06/14] json-lexer: limit the maximum size of a given token X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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; }