[all-commits] [llvm/llvm-project] 1d0760: [lldb][Format] Reject recursive format entities (#...

Michael Buch via All-commits all-commits at lists.llvm.org
Thu Jan 8 08:26:03 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1d07609894f0b07bf739a5ac2c07066ec8c3399c
      https://github.com/llvm/llvm-project/commit/1d07609894f0b07bf739a5ac2c07066ec8c3399c
  Author: Michael Buch <michaelbuch12 at gmail.com>
  Date:   2026-01-08 (Thu, 08 Jan 2026)

  Changed paths:
    M lldb/include/lldb/Core/FormatEntity.h
    M lldb/source/Core/FormatEntity.cpp
    M lldb/test/Shell/Settings/TestCxxFrameFormatRecursive.test

  Log Message:
  -----------
  [lldb][Format] Reject recursive format entities (#174750)

Depends on:
* https://github.com/llvm/llvm-project/pull/174618

If a format entity calls back into `Format` and passes it a format
entity type that we're already in the process of parsing, we are likely
going to run into infinite recursion and blow the stack. I think this is
only an issue when a format entity calls Format on a format string
provided by the user (otherwise we're in control of the recursion). An
example of this can be seen in the test-case adjusted by this patch.

This seems to be causing actual crashes in the field, so this patch adds
basic tracking to `Formatter::Format` that checks whether we're
recursively parsing the same entity. This may very well be intended by
some entities (e.g., `Root` and `Scope`), so there is an escape hatch
for those. There's also a special case where `Variable` causes a
recursive format (which I pointed out in a source comment).

We could narrow the scope of what kind of recursion is allowed by adding
a `UserProvidedFormatChild` (or similar) flag to `Entry`, and only
disallow recursing on those kinds of entries. For now I just use an
exemption list in `IsInvalidRecursiveFormat`.

Adding a unit-test for this is unfortunately tricky because the only
format entity that currently suffers from this is
`${function.name-with-args}`, which requires a language plugin and valid
target. If we really wanted to we could probably mock all of those, but
the shell test provides test coverage for the previously crashing case.

rdar://166890120



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list