Commit Graph

11 Commits

Author SHA1 Message Date
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Dario Lombardo ed40d31801 json_dumper: flush dumper before printing an error.
This helps the developer in the debug phases.

Change-Id: I85558334b5d618219a48a6c00129cd36a6ab0b10
Reviewed-on: https://code.wireshark.org/review/32531
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2019-03-22 22:30:24 +00:00
Peter Wu 089d432040 json_dumper: escape forward slash in some strings
If the JSON output is written in a script tag for a HTML page, be sure
to not to break it.

Change-Id: I1b9ba6a39faf266e8a7bf9befa2899978beb130c
Reviewed-on: https://code.wireshark.org/review/31953
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-12 04:44:00 +00:00
Peter Wu 7cc5941f95 json_dumper: add json_dumper_value_double
Add locale-independent version that replaces json_dumper_value_anyf for
floating-point numbers. NaN and -/+Infinity are mapped to null.

Change-Id: I8e7856de480b7bcafe77ddd015239e1257768ced
Reviewed-on: https://code.wireshark.org/review/31948
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Jakub Zawadzki <jbwzawadzki@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-02-11 05:09:58 +00:00
Dario Lombardo 19d787d051 json_dumper: make json_dumper_bad fatal.
A call to this function means a programming error. g_error makes it
fatal and terminates the program, making the debug easier.

Change-Id: I5c9e82507482733b4d450ed6c3a9fc17fb0fcdca
Reviewed-on: https://code.wireshark.org/review/31310
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-01-03 14:04:23 +00:00
Dario Lombardo e830182d9e json_dumper: add json_dumper_value_va_list().
Change-Id: I8effb701b505e5ce0c06be42ab524c458e1839ce
Reviewed-on: https://code.wireshark.org/review/31207
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2018-12-27 20:19:38 +00:00
Dario Lombardo 71517540b7 json_dumper: add base64 routines.
Change-Id: Iab9a201fe951e5557501f4e675ab74ecd9dbb930
Reviewed-on: https://code.wireshark.org/review/31034
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-23 21:10:47 +00:00
Peter Wu cd41203949 json_dumper: add debugging print as corruption check
Print warnings to help with debugging. Add Jakub (author of
json_puts_string).

Change-Id: I8bf039afc21357e97accb2a9abf9378735af12eb
Reviewed-on: https://code.wireshark.org/review/31041
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-22 00:57:05 +00:00
Dario Lombardo 3f01aaac49 json_dumper: add support to convert dots in underscores.
This is needed for ek json compatibility.

Change-Id: I75c74a1dc7996f3f4c17071508655ae6e3c6b94c
Reviewed-on: https://code.wireshark.org/review/30993
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-10 19:58:25 +00:00
Dario Lombardo 9e4878a8f4 json_dumper: support 'null' json object.
Allow the function json_puts_string() to be called with the NULL
argument that translates to 'null' json object.

Change-Id: I3d2aafad446962d3342ab30b9d509f054d393c64
Reviewed-on: https://code.wireshark.org/review/30978
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-12-09 17:48:34 +00:00
Peter Wu 656cc19fc7 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>
2018-11-20 05:03:56 +00:00