Skip to content

Demo marker contains unguarded use of __FILE__Β #9033

@achabense

Description

@achabense

Version/Branch of Dear ImGui:

Version 1.92.2b

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx9.cpp (and so on)

Compiler, OS:

MSVC (and so on)

Full config/build information:

No response

Details:

#define IMGUI_DEMO_MARKER(section) do { if (GImGuiDemoMarkerCallback != NULL) GImGuiDemoMarkerCallback(__FILE__, __LINE__, section, GImGuiDemoMarkerCallbackUserData); } while (0)

Demo marker introduces the only explicit use of __FILE__ in the imgui library. This makes users calling ShowDemoWindow() at larger risk of exposing their absolute path in the program (especially in release mode), as __FILE__ is expanded to absolute path by default. For example, I find my local path (including private username) being compiled into exe if I compile example/example_win32_directx9 (arbitrarily chosen) in release mode.

Screenshot 2025-10-25 152625

There are many ways to prevent the absolute path - there is IMGUI_DISABLE_DEMO_WINDOWS in the library, and there are compiler options to change __FILE__ to relative path (*). However, it adds more risk for users that are unaware of this problem.

Some ideas:

  1. Make this an opt-in block, i.e. #ifdef-guarded by macro that's configurable in "imconfig.h", and ideally add a comment warning about __FILE__ being absolute path by default, so only users that actually need this feature have to think about this.
  2. Or replace __FILE__ with "imgui_demo.cpp" directly (I'm not familiar with the workings of GImGuiDemoMarkerCallback, so maybe this doesn't work and is not an option.)

See also: libsdl-org/SDL#14290

(*) It's still not enough to prevent all absolute paths... I see another absolute path in the exe (the .pdb file)...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions