drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.62k stars 1.12k forks source link

Crash using config on windows with local debug build #1180

Closed alexgeek closed 6 months ago

alexgeek commented 2 years ago

Describe the bug

I'm using an in repo source build of drogon on Windows with VS Code and using the VS 2022 kit.

When I switch to using use the config I get the following error:

Exception has occurred: W32/0xC0000005
Unhandled exception at 0x00007FFFE5971320 (vcruntime140d.dll) in rp-sync.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

With this call stack:

vcruntime140d.dll!00007fffe5971320() (Unknown Source:0)
rp-sync.exe!std::_Char_traits<char,int>::move(char * const _First1, const char * const _First2, const unsigned __int64 _Count) Line 120 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\xstring:120)
rp-sync.exe!std::string::assign(const char * const _Ptr, const unsigned __int64 _Count) Line 3264 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\xstring:3264)
rp-sync.exe!std::string::_Copy_assign(const std::string & _Right, std::integral_constant<bool,0> __formal) Line 3048 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\xstring:3048)
rp-sync.exe!std::string::operator=(const std::string & _Right) Line 3093 (c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\include\xstring:3093)
rp-sync.exe!drogon::HttpAppFrameworkImpl::setDocumentRoot(const std::string & rootPath) Line 228 (d:\Projects\rp-sync\drogon\lib\src\HttpAppFrameworkImpl.h:228)
rp-sync.exe!loadApp(const Json::Value & app) Line 258 (d:\Projects\rp-sync\drogon\lib\src\ConfigLoader.cc:258)
rp-sync.exe!drogon::ConfigLoader::load() Line 638 (d:\Projects\rp-sync\drogon\lib\src\ConfigLoader.cc:638)
rp-sync.exe!drogon::HttpAppFrameworkImpl::loadConfigFile(const std::string & fileName) Line 387 (d:\Projects\rp-sync\drogon\lib\src\HttpAppFrameworkImpl.cc:387)
rp-sync.exe!main() Line 41 (d:\Projects\rp-sync\main.cc:41)
rp-sync.exe!invoke_main() Line 79 (d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79)
rp-sync.exe!__scrt_common_main_seh() Line 288 (d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
rp-sync.exe!__scrt_common_main() Line 331 (d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331)
rp-sync.exe!mainCRTStartup(void * __formal) Line 17 (d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17)
kernel32.dll!00007ff850717034() (Unknown Source:0)
ntdll.dll!00007ff851be2651() (Unknown Source:0)

The primary suspect lines are at ConfigLoader.cc:253-257

auto documentRoot = app.get("document_root", "").asString();
if (documentRoot != "")
{
    drogon::app().setDocumentRoot(documentRoot);
}

From what I can tell app.get("document_root", "") is returning a corrupted string and then it crashes when it tries to copy assign it.

To Reproduce

  1. Create a project with drogon_ctl
  2. Clone drogon into ./drogon
  3. Adjust CMakeLists.txt to use build and link local drogon rather than find_package
  4. Adjust main.cc to load config.json
  5. Build in Debug build variant with Visual Studio Community 2022 Release - amd64 kit

Expected behavior I expect no crash, I don't get one in Release build variant.

Desktop (please complete the following information):

Additional context cmake version 3.23.0-rc1

marty1885 commented 2 years ago

@alexgeek Sorry for the late reply. May you share a minimal source code and config to trigger it? It's difficult for me to debug this without able to replicate it