1. 11 7月, 2017 5 次提交
  2. 04 4月, 2017 1 次提交
  3. 08 6月, 2016 2 次提交
  4. 25 6月, 2015 5 次提交
    • E
      json: enhance parser test · cb005533
      Eric Blake 提交于
      We already enable the parser option to detect invalid UTF-8, but
      didn't test it.  Also, JSON states that behavior of an object
      with a duplicated key is undefined; we chose to reject it, but
      were not testing it.
      
      With the enhanced tests in place, we can simplify yajl2
      initialization by relying on parser defaults being sane.
      
      * src/util/virjson.c (virJSONValueFromString): Simplify.
      * tests/jsontest.c (mymain): Test more bad usage.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      cb005533
    • E
      json: even stricter trailing garbage detection · 7e191fd9
      Eric Blake 提交于
      Since older yajl ignores trailing garbage, a client can cause
      problems by intentionally ending the wrapper array early. Since
      we already track nesting, it's not too much harder to reject
      invalid nesting pops.
      
      * src/util/virjson. (_virJSONParser): Add field.
      (virJSONValueFromString): Set witness.
      (virJSONParserHandleEndArray): Use it to catch abuse.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7e191fd9
    • E
      json: reject trailing garbage · 7cd991b7
      Eric Blake 提交于
      Yajl 2 has a nice feature that it can be configured whether to
      allow multiple JSON objects parsed from a single stream, defaulting
      to off.  And yajl 1.0.12 at least provided a way to tell if all
      input bytes were parsed, or if trailing bytes remained after a
      valid JSON object was parsed.  But we target RHEL 6 yajl 1.0.7,
      which has neither of these.  So fake it by always parsing '[...]'
      instead, so that trailing garbage either trips up the array parse,
      or is easily detected when unwrapping the result.
      
      * src/util/virjson.c (virJSONValueFromString): With older json,
      wrap text to avoid trailing garbage.
      * tests/jsontest.c (mymain): Add tests for this.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7cd991b7
    • E
      json: reject javascript comments · 54dbba5b
      Eric Blake 提交于
      We have been allowing javascript style comments in JSON ever
      since commit 9428f2ce (v0.7.5), but qemu doesn't send them, and
      they are not strict JSON.  Reject them for now; if we can later
      prove that it is worthwhile, we can reinstate it at that point
      (or even make it conditional, by adding a bool parameter to
      the libvirt entry point).
      
      * src/util/virjson.c (virJSONValueFromString): Don't enable
      comment parsing.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      54dbba5b
    • E
      json: cope with older yajl semantics · f2acaebd
      Eric Blake 提交于
      Commit ceb496e5 fails on RHEL 6, with yajl 1.0.7, because that
      version of yajl returns yajl_status_insufficient_data when the
      parser is waiting for the rest of a token (this enum value was
      dropped in yajl 2, so we have to wrap it).  It also exposes a
      problem where older yajl silently ignores trailing garbage after
      a successful parse, so this patch works around that by changing
      the testsuite.  Another more invasive patch can add tighter
      semantics to json parsing, but this is sufficient for a minimal
      clean backport.
      
      While touching this, fix up our error message cleanup. Yajl
      documents that error messages produced by yajl_get_error()
      MUST be cleaned with yajl_free_error(); this is certainly
      true if we were to pass non-NULL allocator callbacks during
      yajl_alloc(), but probably harmless in our usage of passing
      NULL.  But better safe than sorry.
      
      * src/util/virjson.c (virJSONValueFromString): Allow different
      error code.  Use canonical cleanup of error message.
      (VIR_YAJL_STATUS_OK): New helper macro.
      * tests/jsontest.c (mymain): Wrap text to avoid difference in
      trailing garbage handling
      Signed-off-by: NEric Blake <eblake@redhat.com>
      f2acaebd
  5. 23 6月, 2015 2 次提交
    • E
      json: make it easier to type-check when getting from object · 58fd6703
      Eric Blake 提交于
      While working in qemu_monitor_json, I repeatedly found myself
      getting a value then checking if it was an object.  Add some
      wrappers to make this task easier.
      
      * src/util/virjson.c (virJSONValueObjectGetByType)
      (virJSONValueObjectGetObject, virJSONValueObjectGetArray): New
      functions.
      (virJSONValueObjectGetString, virJSONValueObjectGetNumberInt)
      (virJSONValueObjectGetNumberUint)
      (virJSONValueObjectGetNumberLong)
      (virJSONValueObjectGetNumberUlong)
      (virJSONValueObjectGetNumberDouble)
      (virJSONValueObjectGetBoolean): Simplify.
      (virJSONValueIsNull): Change return type.
      * src/util/virjson.h: Reflect changes.
      * src/libvirt_private.syms (virjson.h): Export them.
      * tests/jsontest.c (testJSONLookup): New test.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      58fd6703
    • E
      json: fully parse input string · ceb496e5
      Eric Blake 提交于
      I was adding a JSON test, and was shocked to find out our parser
      treated the input string of "1" as invalid JSON.  It turns out
      that YAJL specifically documents that it buffers input, and that
      if the last input read could be a prefix to a longer token, then
      you have to explicitly tell the parser that the buffer has ended
      before that token will be processed.
      
      It doesn't help that yajl 2 renamed the function from what it was
      in yajl 1.
      
      * src/util/virjson.c (virJSONValueFromString): Complete parse, in
      case buffer ends in possible token prefix.
      * tests/jsontest.c (mymain): Expose the problem.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      ceb496e5
  6. 11 6月, 2015 1 次提交
  7. 14 5月, 2015 1 次提交
  8. 24 4月, 2015 1 次提交
  9. 25 3月, 2014 1 次提交
  10. 20 11月, 2013 2 次提交
  11. 08 10月, 2013 1 次提交
  12. 02 8月, 2013 1 次提交
    • J
      tests: Coverity found new NULL_RETURNS · 3b4b1214
      John Ferlan 提交于
      Coverity reported the existing missing check of the return value and
      subsequent use from a call to virJSONValueFromString() in testJSONAddRemove().
      3b4b1214
  13. 14 5月, 2013 1 次提交
    • E
      json: support removing a value from an object · 547a7c77
      Eric Blake 提交于
      In an upcoming patch, I need the way to safely transfer a nested
      virJSON object out of its parent container for independent use,
      even after the parent is freed.
      
      * src/util/virjson.h (virJSONValueObjectRemoveKey): New function.
      (_virJSONObject, _virJSONArray): Use correct type.
      * src/util/virjson.c (virJSONValueObjectRemoveKey): Implement it.
      * src/libvirt_private.syms (virjson.h): Export it.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      547a7c77
  14. 21 12月, 2012 1 次提交
  15. 01 7月, 2011 1 次提交
    • D
      Add test case for parsing JSON docs · 06da1805
      Daniel P. Berrange 提交于
      While investigating some memory leaks it was unclear whether the
      JSON code correctly free'd all memory during parsing. Add a test
      case which can be run under valgrind to clearly demonstrate that
      the parser is leak free.
      
      * tests/Makefile.am: Add 'jsontest'
      * tests/jsontest.c: A few simple JSON parsing tests
      06da1805