Commit Graph

12 Commits

Author SHA1 Message Date
Andrew Berry
5e20bd2c40 Fix http server truncating large get_stats/get_protocols JSON
The /cmd getters serialized into fixed stack buffers (get_stats 20480,
get_meta 2048, get_protocols 102400). When a report exceeded its buffer
the output was silently corrupted into invalid JSON, not cleanly
truncated: the abuf string builder drops an oversized chunk but keeps
appending the smaller chunks that follow, so e.g. a get_stats reply with
~230 enabled decoders ended like `...,"name":,:8256}`. Clients then fail
to parse the response and the corresponding data never updates.

Make the serializer report truncation and add data_print_jsons_dup(),
which grows a heap buffer until the whole document fits, and use it for
the three JSON-payload getters:

- abuf gains an `overflow` flag, set by abuf_cat/abuf_printf and the
  hand-rolled string formatter whenever a write is dropped or truncated.
- data_print_jsons_dup() retries with a doubled buffer until no overflow
  (64 MiB sanity cap), so the report is never truncated.
- get_stats/get_meta/get_protocols use it and free the buffer after
  responding; out-of-memory yields an error reply instead of a partial one.

Tests:
- data-test asserts a large report serializes to a complete object via
  data_print_jsons_dup() while a fixed undersized buffer does not.
- the HTTP integration test now validates that get_protocols/get_stats/
  get_meta return parseable JSON, not just HTTP 200.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 13:43:12 +02:00
Christian W. Zuckschwerdt
55d5385c88 minor: Fix more unexpected chars in input files 2024-02-07 19:34:39 +01:00
Christian W. Zuckschwerdt
0ff7247336 Add output log level options (#2282) 2022-12-19 18:44:29 +01:00
Christian W. Zuckschwerdt
1aa49c04f5 Fix deprecated function prototypes 2022-11-14 17:46:17 +01:00
Christian W. Zuckschwerdt
305edc44f9 Refactor file outputs from data 2021-12-08 12:00:42 +01:00
Christian W. Zuckschwerdt
1bed1426b4 Refactor csv_init to output_start 2018-12-19 11:56:34 +01:00
Christian W. Zuckschwerdt
4e16269734 Fix csv output by initializing the fields after protocol options 2018-11-20 13:24:22 +01:00
Christian W. Zuckschwerdt
64c3177a7f remove output_hander_t, printer_ctx indirection 2018-01-28 13:19:21 +01:00
Erkki Seppälä
a3f7561a61 data: added CSV support
This requires the client code to first collect the permitted CSV fields
and use data_csv_init to pass them to the CSV builder.
2015-11-23 23:47:54 +02:00
Erkki Seppälä
06c4d39c4a data: introduce auxiliary data as an argument 2015-11-23 23:47:54 +02:00
Erkki Seppälä
17eb918cde data: provide a key-value-printer 2015-11-23 23:47:54 +02:00
Erkki Seppälä
44d0740a8c General structural data support for generating (ie.) JSON
Adds a new interface for constructing, printing and releasing data_t*
structures. The data structure describes typed hierarchical data (much like
json) and then provides a function for dumping it to a file descriptor.

It comes with a small test.
2015-11-22 12:25:58 +02:00