1. 14 12月, 2018 1 次提交
  2. 25 8月, 2018 1 次提交
    • M
      qjson: Have qobject_from_json() & friends reject empty and blank · dd98e848
      Markus Armbruster 提交于
      The last case where qobject_from_json() & friends return null without
      setting an error is empty or blank input.  Callers:
      
      * block.c's parse_json_protocol() reports "Could not parse the JSON
        options".  It's marked as a work-around, because it also covered
        actual bugs, but they got fixed in the previous few commits.
      
      * qobject_input_visitor_new_str() reports "JSON parse error".  Also
        marked as work-around.  The recent fixes have made this unreachable,
        because it currently gets called only for input starting with '{'.
      
      * check-qjson.c's empty_input() and blank_input() demonstrate the
        behavior.
      
      * The other callers are not affected since they only pass input with
        exactly one JSON value or, in the case of negative tests, one error.
      
      Fail with "Expecting a JSON value" instead of returning null, and
      simplify callers.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <20180823164025.12553-48-armbru@redhat.com>
      dd98e848
  3. 04 5月, 2018 2 次提交
  4. 20 3月, 2018 2 次提交
  5. 09 2月, 2018 5 次提交
  6. 24 7月, 2017 1 次提交
  7. 20 6月, 2017 3 次提交
  8. 19 6月, 2017 1 次提交
  9. 31 5月, 2017 1 次提交
    • M
      qobject-input-visitor: Reject non-finite numbers with keyval · 5891c388
      Markus Armbruster 提交于
      The QObject input visitor can produce only finite numbers when its
      input comes out of the JSON parser, because the the JSON parser
      implements RFC 7159, which provides no syntax for infinity and NaN.
      
      However, it can produce infinity and NaN when its input comes out of
      keyval_parse(), because we parse with strtod() then.
      
      The keyval variant should not be able to express things the JSON
      variant can't.  Rejecting non-finite numbers there is the conservative
      fix.  It's also minimally invasive.
      
      We could instead extend our JSON dialect to provide for infinity and
      NaN.  Not today.
      
      Note that the JSON formatter can emit non-finite numbers (marked FIXME
      in commit 6e8e5cb9).
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1495471335-23707-2-git-send-email-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Reviewed-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
      5891c388
  10. 09 5月, 2017 2 次提交
  11. 07 3月, 2017 6 次提交
    • M
      keyval: Support lists · 0b2c1bee
      Markus Armbruster 提交于
      Additionally permit non-negative integers as key components.  A
      dictionary's keys must either be all integers or none.  If all keys
      are integers, convert the dictionary to a list.  The set of keys must
      be [0,N].
      
      Examples:
      
      * list.1=goner,list.0=null,list.1=eins,list.2=zwei
        is equivalent to JSON [ "null", "eins", "zwei" ]
      
      * a.b.c=1,a.b.0=2
        is inconsistent: a.b.c clashes with a.b.0
      
      * list.0=null,list.2=eins,list.2=zwei
        has a hole: list.1 is missing
      
      Similar design flaw as for objects: there is no way to denote an empty
      list.  While interpreting "key absent" as empty list seems natural
      (removing a list member from the input string works when there are
      multiple ones, so why not when there's just one), it doesn't work:
      "key absent" already means "optional list absent", which isn't the
      same as "empty list present".
      
      Update the keyval object visitor to use this a.0 syntax in error
      messages rather than the usual a[0].
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1488317230-26248-25-git-send-email-armbru@redhat.com>
      [Off-by-one fix squashed in, as per Kevin's review]
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      0b2c1bee
    • M
      qapi: Improve how keyval input visitor reports unexpected dicts · 31478f26
      Markus Armbruster 提交于
      Incorrect option
      
          -blockdev node-name=foo,driver=file,filename=foo.img,aio.unmap=on
      
      is rejected with "Invalid parameter type for 'aio', expected: string".
      To make sense of this, you almost have to translate it into the
      equivalent QMP command
      
          { "execute": "blockdev-add", "arguments": { "node-name": "foo", "driver": "file", "filename": "foo.img", "aio": { "unmap": true } } }
      
      Improve the error message to "Parameters 'aio.*' are unexpected".
      Take care not to confuse the case "unexpected nested parameters"
      (i.e. the object is a QDict or QList) with the case "non-string scalar
      parameter".  The latter is a misuse of the visitor, and should perhaps
      be an assertion.  Note that test-qobject-input-visitor exercises this
      misuse in test_visitor_in_int_keyval(), test_visitor_in_bool_keyval()
      and test_visitor_in_number_keyval().
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Message-Id: <1488317230-26248-23-git-send-email-armbru@redhat.com>
      31478f26
    • M
      qapi: New qobject_input_visitor_new_str() for convenience · 9d1eab4b
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1488317230-26248-21-git-send-email-armbru@redhat.com>
      9d1eab4b
    • M
      qapi: Factor out common qobject_input_get_keyval() · e3934b42
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488317230-26248-8-git-send-email-armbru@redhat.com>
      e3934b42
    • M
      qapi: Factor out common part of qobject input visitor creation · abe81bc2
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Message-Id: <1488317230-26248-7-git-send-email-armbru@redhat.com>
      abe81bc2
    • D
      qapi: qobject input visitor variant for use with keyval_parse() · cbd8acf3
      Daniel P. Berrange 提交于
      Currently the QObjectInputVisitor assumes that all scalar values are
      directly represented as the final types declared by the thing being
      visited. i.e. it assumes an 'int' is using QInt, and a 'bool' is using
      QBool, etc.  This is good when QObjectInputVisitor is fed a QObject
      that came from a JSON document on the QMP monitor, as it will strictly
      validate correctness.
      
      To allow QObjectInputVisitor to be reused for visiting a QObject
      originating from keyval_parse(), an alternative mode is needed where
      all the scalars types are represented as QString and converted on the
      fly to the final desired type.
      Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
      Message-Id: <1475246744-29302-8-git-send-email-berrange@redhat.com>
      
      Rebased, conflicts resolved, commit message updated to refer to
      keyval_parse().  autocast replaced by keyval in identifiers,
      noautocast replaced by fail in tests.
      
      Fix qobject_input_type_uint64_keyval() not to reject '-', for QemuOpts
      compatibility: replace parse_uint_full() by open-coded
      parse_option_number().  The next commit will add suitable tests.
      Leave out the fancy ERANGE error reporting for now, but add a TODO
      comment.  Add it qobject_input_type_int64_keyval() and
      qobject_input_type_number_keyval(), too.
      
      Open code parse_option_bool() and parse_option_size() so we have to
      call qobject_input_get_name() only when actually needed.  Again, leave
      out ERANGE error reporting for now.
      
      QAPI/QMP downstream extension prefixes __RFQDN_ don't work, because
      keyval_parse() splits them at '.'.  This will be addressed later in
      the series.
      
      qobject_input_type_int64_keyval(), qobject_input_type_uint64_keyval(),
      qobject_input_type_number_keyval() tweaked for style.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NKevin Wolf <kwolf@redhat.com>
      Message-Id: <1488317230-26248-5-git-send-email-armbru@redhat.com>
      cbd8acf3
  12. 05 3月, 2017 8 次提交
    • M
      qapi: Fix object input visit beyond end of list · 1f41a645
      Markus Armbruster 提交于
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-28-git-send-email-armbru@redhat.com>
      1f41a645
    • M
      qapi: Make input visitors detect unvisited list tails · a4a1c70d
      Markus Armbruster 提交于
      Fix the design flaw demonstrated in the previous commit: new method
      check_list() lets input visitors report that unvisited input remains
      for a list, exactly like check_struct() lets them report that
      unvisited input remains for a struct or union.
      
      Implement the method for the qobject input visitor (straightforward),
      and the string input visitor (less so, due to the magic list syntax
      there).  The opts visitor's list magic is even more impenetrable, and
      all I can do there today is a stub with a FIXME comment.  No worse
      than before.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Message-Id: <1488544368-30622-26-git-send-email-armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      a4a1c70d
    • M
      qapi: Drop unused non-strict qobject input visitor · 048abb7b
      Markus Armbruster 提交于
      The split between tests/test-qobject-input-visitor.c and
      tests/test-qobject-input-strict.c now makes less sense than ever.  The
      next commit will take care of that.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-20-git-send-email-armbru@redhat.com>
      048abb7b
    • M
      qapi: Improve qobject input visitor error reporting · a9fc37f6
      Markus Armbruster 提交于
      Error messages refer to nodes of the QObject being visited by name.
      Trouble is the names are sometimes less than helpful:
      
      * The name of the root QObject is whatever @name argument got passed
        to the visitor, except NULL gets mapped to "null".  We commonly pass
        NULL.  Not good.
      
        Avoiding errors "at the root" mitigates.  For instance,
        visit_start_struct() can only fail when the visited object is not a
        dictionary, and we commonly ensure it is beforehand.
      
      * The name of a QDict's member is the member key.  Good enough only
        when this happens to be unique.
      
      * The name of a QList's member is "null".  Not good.
      
      Improve error messages by referring to nodes by path instead, as
      follows:
      
      * The path of the root QObject is whatever @name argument got passed
        to the visitor, except NULL gets mapped to "<anonymous>".
      
      * The path of a root QDict's member is the member key.
      
      * The path of a root QList's member is "[%u]", where %u is the list
        index, starting at zero.
      
      * The path of a non-root QDict's member is the path of the QDict
        concatenated with "." and the member key.
      
      * The path of a non-root QList's member is the path of the QList
        concatenated with "[%u]", where %u is the list index.
      
      For example, the incorrect QMP command
      
          { "execute": "blockdev-add", "arguments": { "node-name": "foo", "driver": "raw", "file": {"driver": "file" } } }
      
      now fails with
      
          {"error": {"class": "GenericError", "desc": "Parameter 'file.filename' is missing"}}
      
      instead of
      
          {"error": {"class": "GenericError", "desc": "Parameter 'filename' is missing"}}
      
      and
      
          { "execute": "input-send-event", "arguments": { "device": "bar", "events": [ [] ] } }
      
      now fails with
      
          {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'events[0]', expected: object"}}
      
      instead of
      
          {"error": {"class": "GenericError", "desc": "Invalid parameter type for 'null', expected: QDict"}}
      
      Aside: calling the thing "parameter" is suboptimal for QMP, because
      the root object is "arguments" there.
      
      The qobject output visitor doesn't have this problem because it should
      not fail.  Same for dealloc and clone visitors.
      
      The string visitors don't have this problem because they visit just
      one value, whose name needs to be passed to the visitor as @name.  The
      string output visitor shouldn't fail anyway.
      
      The options visitor uses QemuOpts names.  Their name space is flat, so
      the use of QDict member keys as names is fine.  NULL names used with
      roots and lists could conceivably result in bad error messages.  Left
      for another day.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-15-git-send-email-armbru@redhat.com>
      a9fc37f6
    • M
      qapi: Make QObject input visitor set *list reliably · 58561c27
      Markus Armbruster 提交于
      qobject_input_start_struct() sets *list, except when it fails because
      qobject_input_get_object() fails, i.e. the input object doesn't exist.
      
      All the other input visitor start_struct(), start_list(),
      start_alternate() always set *obj / *list.
      
      Change qobject_input_start_struct() to match.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-14-git-send-email-armbru@redhat.com>
      Reviewed-by: NPhilippe Mathieu-Daudé <f4bug@amsat.org>
      58561c27
    • M
      qapi: Clean up after commit 3d344c2a · b8874fbf
      Markus Armbruster 提交于
      Drop unused QIV_STACK_SIZE and unused qobject_input_start_struct()
      parameter errp.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-13-git-send-email-armbru@redhat.com>
      b8874fbf
    • M
      qapi: Improve a QObject input visitor error message · 910f738b
      Markus Armbruster 提交于
      The QObject input visitor has three error message formats:
      
      * Parameter '%s' is missing
      * "Invalid parameter type for '%s', expected: %s"
      * "QMP input object member '%s' is unexpected"
      
      The '%s' are member names (or "null", but I'll fix that later).
      
      The last error message calls the thing "QMP input object member"
      instead of "parameter".  Misleading when the visitor is used on
      QObjects that don't come from QMP.  Change it to "Parameter '%s' is
      unexpected".
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-12-git-send-email-armbru@redhat.com>
      910f738b
    • M
      qmp: Eliminate silly QERR_QMP_* macros · 99fb0c53
      Markus Armbruster 提交于
      The QERR_ macros are leftovers from the days of "rich" error objects.
      
      QERR_QMP_BAD_INPUT_OBJECT, QERR_QMP_BAD_INPUT_OBJECT_MEMBER,
      QERR_QMP_EXTRA_MEMBER are used in just one place now, except for one
      use that has crept into qobject-input-visitor.c.
      
      Drop these macros, to make the (bad) error messages more visible.
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      Message-Id: <1488544368-30622-10-git-send-email-armbru@redhat.com>
      99fb0c53
  13. 25 10月, 2016 2 次提交
  14. 08 10月, 2016 3 次提交
  15. 06 10月, 2016 1 次提交
  16. 19 7月, 2016 1 次提交
    • P
      qapi: change QmpInputVisitor to QSLIST · 3d344c2a
      Paolo Bonzini 提交于
      This saves a lot of memory compared to a statically-sized array,
      or at least 24kb could be considered a lot on an Atari ST.
      It also makes the code more similar to QmpOutputVisitor.
      
      This removes the limit on the depth of a QObject that can be processed
      into a QAPI tree.  This is not a problem because QObjects can be
      considered trusted; the text received on the QMP wire is untrusted
      input, but the JSON parser already takes pains to limit the QObject tree
      it creates.  We don't need the QMP input visitor to limit it again.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <1467906798-5312-3-git-send-email-pbonzini@redhat.com>
      Reviewed-by: NMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: NEric Blake <eblake@redhat.com>
      [Commit message typo fixed]
      Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
      3d344c2a