Skip to content

[BUG] Structured logging must pass GLIB_DOMAIN as nul-terminated string #1538

@swsnr

Description

@swsnr

Bug description

Currently, log_structured! passes GLIB_DOMAIN as a log field with byte value and explicit length. However, GLib expects GLIB_DOMAIN to be a nul-terminated C string, see should_drop_message which calls domain_found which in turn uses strlen on the domain value.

This breaks debug logging for Rust domains via $G_MESSAGES_DEBUG, because GLib fails to find the domain in the environment variable, see #1534

I'm only superficially familiar with C, and haven't checked the entire call stack, but it also seems that passing GLIB_DOMAIN as field with explicit length, i.e. omitting the final NUL byte from the field value, probably even leads to out-of-bounds memory access in GLib 🤔

I'm not sure whether this constitutes an issue in GLib, but it can be fixed on the Rust side by passing the domain as nul-terminated string, at the cost of one allocation. I'll make a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions