Open Bug 2094687 Opened 12 days ago Updated 12 days ago

Reject C++ log module names that MOZ_LOG cannot parse at compile time

Categories

(Core :: XPCOM, task)

task

Tracking

()

ASSIGNED

People

(Reporter: dcarver, Assigned: dcarver)

References

(Blocks 2 open bugs)

Details

Attachments

(2 external files)

The rules for what makes a valid log module name are not written down anywhere. NSPRLogModulesParser accepts names that start with - or contain * anywhere, and nothing checks the names given to LazyLogModule, so a C++ module can be declared under a name that MOZ_LOG cannot configure. Bug 2084279 renamed one such module, 3pcbexception, which MOZ_LOG stopped reading at because of its leading digit.

Proposal:

  • Define the valid names in one header in mozglue, LogModuleName.h, with no parser in it, so any header can check a name. It provides IsValidLogModuleName and the matching regexes:
    • A C++ name is a single segment of ASCII letters, digits, _, - and ., which doesn't start with a digit or -. That way a misplaced level or flag, such as 5 or -m, can't be mistaken for a module name.
    • A Rust module path or tracing target has two or more such segments separated by ::. The last one can be *, as in neqo_transport::*.
  • Make the LazyLogModule constructor consteval, so a name that isn't a valid C++ name fails the build. All existing names already pass.

The new MOZ_LOG parser (bug 2080769) checks module names with the same regexes, and the mozilla/valid-log-module ESLint rule (bug 2086992) applies the C++ form to the logModule of JS consoles.

Names created at run time through LogModule::Get, as from JS consoles or logging.<name> prefs, are not checked here. Bug 2079145 covers those.

A log module name is either a C++ name, a single segment, or a Rust module
path or tracing target, segments separated by ::, the last of which can be
*. A segment is made of ASCII letters, digits, '_', '-' and '.', and doesn't
start with a digit or '-', so that a misplaced level or flag can't be mistaken
for a name.

This grammar is stricter than what NSPRLogModulesParser reads today, which
also takes names starting with '-' or containing '*' anywhere. It is meant to
be the grammar of the log module names in MOZ_LOG.

IsValidLogModuleName and the regexes of the log module names live in
LogModuleName.h, apart from any parser, so that a header can check a name
without bringing a parser in.

The constructor of LazyLogModule is now consteval, so a name that isn't a
valid C++ log module name, as IsValidCppLogModuleName tells, fails the build.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: