]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
json: Avoid passing large positive 64 bit integers to QMP.
authorRichard W.M. Jones <rjones@redhat.com>
Wed, 25 May 2011 16:52:26 +0000 (17:52 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Wed, 25 May 2011 20:30:39 +0000 (21:30 +0100)
http://lists.gnu.org/archive/html/qemu-devel/2011-05/threads.html#02162

Currently, qemu silently clips any JSON integer in the range
0x8000000000000000 - 0xffffffffffffffff (all numbers in this range
will be clipped to 0x7fffffffffffffff == LLONG_MAX).

To avoid this, pass these as signed 64 bit integers in the QMP
request.

src/qemu/qemu_monitor_json.c

index 2d8a390cef5fde67e6b739be4be4bd3f15f726f1..bdd0dcb3badfa43d274a88d25e8974ca3467ab29 100644 (file)
@@ -413,8 +413,13 @@ qemuMonitorJSONMakeCommand(const char *cmdname,
             ret = virJSONValueObjectAppendNumberLong(jargs, key, val);
         }   break;
         case 'U': {
-            unsigned long long val = va_arg(args, unsigned long long);
-            ret = virJSONValueObjectAppendNumberUlong(jargs, key, val);
+            /* qemu silently truncates numbers larger than LLONG_MAX,
+             * so passing the full range of unsigned 64 bit integers
+             * is not safe here.  Pass them as signed 64 bit integers
+             * instead.
+             */
+            long long val = va_arg(args, long long);
+            ret = virJSONValueObjectAppendNumberLong(jargs, key, val);
         }   break;
         case 'd': {
             double val = va_arg(args, double);