From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:60725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVKs-0006L2-Ox for qemu-devel@nongnu.org; Mon, 23 May 2011 09:38:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOVKr-0005YZ-O8 for qemu-devel@nongnu.org; Mon, 23 May 2011 09:38:18 -0400 Received: from mail-gw0-f45.google.com ([74.125.83.45]:45962) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVKr-0005YV-KJ for qemu-devel@nongnu.org; Mon, 23 May 2011 09:38:17 -0400 Received: by gwb19 with SMTP id 19so2454026gwb.4 for ; Mon, 23 May 2011 06:38:17 -0700 (PDT) Message-ID: <4DDA6347.5020906@codemonkey.ws> Date: Mon, 23 May 2011 08:38:15 -0500 From: Anthony Liguori MIME-Version: 1.0 References: <20110520180331.GA21837@amd.home.annexia.org> <4DD6AEB9.6060506@codemonkey.ws> <20110523130411.GR24143@redhat.com> In-Reply-To: <20110523130411.GR24143@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qemu: json: Fix parsing of integers >= 0x8000000000000000 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: qemu-devel@nongnu.org, "Richard W.M. Jones" , Luiz Capitulino On 05/23/2011 08:04 AM, Daniel P. Berrange wrote: > On Fri, May 20, 2011 at 01:11:05PM -0500, Anthony Liguori wrote: >> On 05/20/2011 01:03 PM, Richard W.M. Jones wrote: >>> >>> There seem to be a few unsafe uses of strto* functions. This patch >>> just fixes the one that affects me :-) >> >> Sending an integer of this size is not valid JSON. >> >> Your patch won't accept negative numbers, correct? >> >> JSON only supports int64_t. > > That's not really true. JSON supports arbitrarily large numbers > & integers. This really blows my mind: alert(9223372036854775807 == 9223372036854775808); Regards, Anthony Liguori It is merely the QEMU parser / object model which > is artifically limiting them to int64_t. The core of the problem > is with the QInt implementation in QEMU, which uses an 'int64_t' > as its canonical form, rather than just holding a string representation > of the number. The JSON parser should only validate that the > data is a valid JSON number, and then pass the number as a string > to QInt. The conversion to int_64 or other integer sizes / formats > should be done at time of use, according to the type of data the > command actually wants, whether int64t, int32t, int16t etc. eg the > QInt API should look more like: > > QInt *qint_from_string(const char *number); > QInt *qint_from_int64(int64_t val); > QInt *qint_from_int32(int64_t val); > QInt *qint_from_int16(int64_t val); > QInt *qint_from_uint64(uint64_t val); > QInt *qint_from_uint32(uint32_t val); > QInt *qint_from_uint16(uint16_t val); > > int qint_get_int64(QInt *qi, int64t *val); > int qint_get_int32(QInt *qi, int32t *val); > int qint_get_int16(QInt *qi, int16t *val); > int qint_get_uint64(QInt *qi, uint64t *val); > int qint_get_uint32(QInt *qi, uint32t *val); > int qint_get_uint16(QInt *qi, uint16t *val); > > > Regards, > Daniel