Replace JSON-GLib by custom JSON dumper library
authorPeter Wu <peter@lekensteyn.nl>
Tue, 20 Nov 2018 01:47:36 +0000 (02:47 +0100)
committerAnders Broman <a.broman58@gmail.com>
Tue, 20 Nov 2018 05:03:56 +0000 (05:03 +0000)
commit656cc19fc7de25c3ac7f9d847c37745ccc272247
tree79de668a68c25fd5bfe8ac2ee36d5b18824fa653
parentfb9c6905eff10f6f49a433ead8bd78e232fa068d
Replace JSON-GLib by custom JSON dumper library

The (optional) JSON-GLib library adds dependencies on GObject, GIO. For
statically linked oss-fuzz builds it also adds libffi and more. To avoid
these dependencies, replace JSON-GLib by some custom code. This allows
`tshark -G elastic-mapping` to be enabled by default without extra deps.

API design goals of the new JSON dumper library:

- Small interface without a lot of abstraction.
- Avoid memory allocations if possible (currently none, but maybe
  json_puts_string will be replaced to improve UTF-8 support).
- Do not implement parsing, this is currently handled by jsmn.

Methods to open/close array/objects and to set members are inspired by
the JsonGlib interface. The interfaces to write values is inspired by
the sharkd code (json_puts_string is also borrowed from that).

The only observed differences in the tshark output:
- JSON-GLib ignores duplicates, json_dumper does not and may produce
  duplicates and currently print two "ip.opt.sec_prot_auth_unassigned".
- JSON-GLib adds a space before a colon (unimportant formatting detail).
- (Not observed, but UTF-8 strings will be wrong like bug 14948.)

A test was added to catch changes in the tshark output. I also fuzzed
json_dumper with libFuzzer + UBSAN/ASAN and fixed an off-by-one error.

Change-Id: I0c85b18777b04d1e0f613a3d59935ec59be87ff4
Link: https://www.wireshark.org/lists/wireshark-dev/201811/msg00052.html
Reviewed-on: https://code.wireshark.org/review/30732
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
debian/libwsutil0.symbols
epan/proto.c
epan/proto.h
test/baseline/elastic-mapping-ip-subset.json [new file with mode: 0644]
test/suite_clopts.py
tshark.c
wsutil/CMakeLists.txt
wsutil/json_dumper.c [new file with mode: 0644]
wsutil/json_dumper.h [new file with mode: 0644]