From patchwork Fri May 20 18:03:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Richard W.M. Jones" X-Patchwork-Id: 96656 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 C19DDB71A1 for ; Sat, 21 May 2011 04:03:53 +1000 (EST) Received: from localhost ([::1]:59153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNU3D-0000RE-3R for incoming@patchwork.ozlabs.org; Fri, 20 May 2011 14:03:51 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNU2y-0000Qd-S2 for qemu-devel@nongnu.org; Fri, 20 May 2011 14:03:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNU2x-0006m4-QU for qemu-devel@nongnu.org; Fri, 20 May 2011 14:03:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNU2x-0006lv-FW for qemu-devel@nongnu.org; Fri, 20 May 2011 14:03:35 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4KI3Wbw029227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 May 2011 14:03:32 -0400 Received: from localhost (vpn1-7-221.ams2.redhat.com [10.36.7.221]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4KI3VPE009018; Fri, 20 May 2011 14:03:32 -0400 Date: Fri, 20 May 2011 19:03:31 +0100 From: "Richard W.M. Jones" To: qemu-devel@nongnu.org Message-ID: <20110520180331.GA21837@amd.home.annexia.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Luiz Capitulino Subject: [Qemu-devel] [PATCH] qemu: json: Fix parsing of integers >= 0x8000000000000000 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 There seem to be a few unsafe uses of strto* functions. This patch just fixes the one that affects me :-) Rich. diff --git a/json-parser.c b/json-parser.c index 6c06ef9..3747ba5 100644 --- a/json-parser.c +++ b/json-parser.c @@ -512,6 +512,8 @@ static QObject *parse_literal(JSONParserContext *ctxt, QList **tokens) { QObject *token, *obj; QList *working = qlist_copy(*tokens); + const char *token_str; + unsigned long long ull; token = qlist_pop(working); switch (token_get_type(token)) { @@ -519,7 +521,14 @@ static QObject *parse_literal(JSONParserContext *ctxt, QList **tokens) obj = QOBJECT(qstring_from_escaped_str(ctxt, token)); break; case JSON_INTEGER: - obj = QOBJECT(qint_from_int(strtoll(token_get_value(token), NULL, 10))); + token_str = token_get_value(token); + errno = 0; + ull = strtoull(token_str, NULL, 10); + if (errno != 0) { + parse_error(ctxt, token, "invalid integer: %s", strerror(errno)); + return NULL; + } + obj = QOBJECT(qint_from_int(ull)); break; case JSON_FLOAT: /* FIXME dependent on locale */