Skip to content

diagnostic_remote_logging: escape InfluxDB line-protocol special characters in diagnostic text - #694

Open
ucsurf wants to merge 1 commit into
ros:ros2from
ucsurf:fix-influx-line-protocol-escaping
Open

ucsurf wants to merge 1 commit into
ros:ros2from
ucsurf:fix-influx-line-protocol-escaping

Conversation

@ucsurf

@ucsurf ucsurf commented Dec 4, 2026

Copy link
Copy Markdown

Hello maintainers,

Thanks for diagnostic_remote_logging. While reading influx_line_protocol.hpp at 33029d0 (ros2 branch, v4.5.7, 2026-11-04) we noticed a robustness issue in how diagnostic text is written to InfluxDB. This was found by source review only; nothing was built or run against an InfluxDB server, and the line-protocol behaviour below comes from the published InfluxDB line-protocol spec.

What happens

  • escapeSpace() is the only escaping helper, and it escapes spaces only.
  • statusToInfluxLineProtocol() uses it for the measurement, the ns/name/hardware_id tags and the field keys. A comma or equals sign in those strings is not escaped, although the spec requires it (measurements: comma and space; tag keys/values and field keys: comma, equals and space).
  • The message field and string values in formatValues() are wrapped in double quotes without escaping " or . A message containing a double quote ends the string early, so the rest of the line is not parsed as intended.
  • A newline in message, in the identifying strings or in a key is written as-is, and InfluxDB treats a newline as the end of a point. formatValues() already skips values that contain a newline, but the other fields are not covered.
  • is_number() does not check finiteness. Whether "nan", "inf" or "1e999" parse as doubles depends on the standard library (we expect libstdc++ and libc++ to reject them and MSVC to accept them); if they parse, they are written as raw literals, which line protocol does not accept.

Why it matters
Ordinary text such as a message with a quote, or a hardware_id like "dev,rev=2", can produce a line InfluxDB rejects. InfluxDB rejects whole write batches that contain invalid lines, so one odd status can stop the other diagnostics in that batch from being recorded. It can also make a point land with different tags or fields than intended. Diagnostics text often comes from third-party drivers, so this is worth making robust. We think it is a correctness and hardening fix, not a security report.

Fix (this PR)
Escape per position per the spec, with separate helpers for measurement, tag/field-key and quoted-string-value; drop newlines (they cannot be escaped in line protocol); and treat non-finite numeric-looking values as quoted strings. The change touches influx_line_protocol.hpp and test/influx_line_protocol.cpp (regression tests added). It applies cleanly at 33029d0 (ros2 HEAD) and passes git apply --check. The header was only stub-compiled by us; the full package and tests have not been built or run, so please let CI confirm. Behaviour changes to be aware of: newlines in diagnostic text are dropped, and nan/inf-like values become quoted strings.

Credit: Ugur Celik (ucsurf), @ucsurf

— Ugur Celik (ucsurf) · https://uc.surf
We find and report security issues in open source before attackers do. If our work helped you, a small contribution keeps it going and makes the internet a little safer for everyone:
https://buymeacoffee.com/ucsurf

…acters

Escape diagnostic text per position as the InfluxDB line protocol requires:
commas and spaces in measurements, commas/equals/spaces in tag keys, tag
values and field keys, and quotes/backslashes in string field values.
Newlines are dropped because a newline ends a point and cannot be escaped.
Non-finite numeric-looking values are written as quoted strings.

Adds regression tests. Not built or run against a real package; source
review only.

Signed-off-by: Ugur Celik (ucsurf) <337280806+ucsurf@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant