Skip to content

ODR violation: httplib.h included with and without CPPHTTPLIB_OPENSSL_SUPPORT across TUs #1

Description

@icemansparks

Problem

src/LuaEngine/HttpManager.h includes the vendored libs/httplib.h without CPPHTTPLIB_OPENSSL_SUPPORT, while HttpManager.cpp defines the macro before including it. Every other TU that pulls HttpManager.h (e.g. via GlobalMethods.h) therefore instantiates the non-SSL variant of cpp-httplib's inline functions, while HttpManager.cpp instantiates the SSL variant.

The macro changes httplib::ClientImpl's member layout and inline function bodies, so the binary ends up with two divergent definitions under identical mangled symbols - an ODR violation. The linker keeps one copy per symbol and freely mixes the two layouts. Whether the https path works is linker luck, not correctness.

Evidence this is real, not theoretical

This exact mechanism crashed the Merkerhood worldserver: mod-discordBot vendors the same httplib 0.13.1 with the SSL macro, the linker mixed its instantiation with mod-ale's non-SSL one, and the first real https POST SIGSEGV'd on a member read at the wrong offset (Merkerhood/mod-discordBot#5, core backtrace shows one call chain interleaving both copies with scrambled arguments; fixed on the discordBot side by namespace isolation in Merkerhood/mod-discordBot#6).

mod-discordBot is now immune, but mod-ale's own instantiations still disagree with each other: Lua HttpRequest against an https URL can hit the same class of corruption depending on which symbol copies the linker keeps.

Suggested fix

Make every include of libs/httplib.h see the same macro configuration. Simplest: move #define CPPHTTPLIB_OPENSSL_SUPPORT into HttpManager.h directly above its #include "libs/httplib.h" (and drop the now-redundant define in HttpManager.cpp, keeping include order so the .h comes first). Alternatively hoist the define into the build flags for the module.

Verification idea

After the fix, nm -C over the mod-ale objects should show a single consistent set of httplib:: symbols, and a Lua script doing an https HttpRequest should round-trip cleanly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions