Skip to content

Commit e07c8cb

Browse files
committed
Use std::vector instead
1 parent aa38b4e commit e07c8cb

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/ServerErrorHandler.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@
99
class ServerErrorHandler : public REQUEST_HANDLER
1010
{
1111
public:
12-
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, BYTE* content, int length) noexcept
13-
: ServerErrorHandler(pContext, statusCode, subStatusCode, statusText, hr, module, disableStartupPage, 0, content, length)
12+
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, const std::string& statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page) noexcept
13+
: ServerErrorHandler(pContext, statusCode, subStatusCode, statusText, hr, module, disableStartupPage, page, std::vector<byte>())
1414
{
1515
}
1616

17-
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page) noexcept
18-
: ServerErrorHandler(pContext, statusCode, subStatusCode, statusText, hr, module, disableStartupPage, page, nullptr, 0)
19-
{
20-
}
21-
22-
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, std::string statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page, BYTE* content, int length) noexcept
17+
ServerErrorHandler(IHttpContext& pContext, USHORT statusCode, USHORT subStatusCode, const std::string& statusText, HRESULT hr, HINSTANCE module, bool disableStartupPage, int page, const std::vector<byte>& content) noexcept
2318
: REQUEST_HANDLER(pContext),
2419
m_pContext(pContext),
2520
m_HR(hr),
@@ -29,7 +24,6 @@ class ServerErrorHandler : public REQUEST_HANDLER
2924
m_statusText(std::move(statusText)),
3025
m_page(page),
3126
m_ExceptionInfoContent(content),
32-
m_length(length),
3327
m_moduleInstance(module)
3428
{
3529
}
@@ -60,10 +54,10 @@ class ServerErrorHandler : public REQUEST_HANDLER
6054
);
6155

6256
dataChunk.DataChunkType = HttpDataChunkFromMemory;
63-
if (m_length > 0)
57+
if (m_ExceptionInfoContent.size() > 0)
6458
{
65-
dataChunk.FromMemory.pBuffer = m_ExceptionInfoContent;
66-
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(m_length);
59+
dataChunk.FromMemory.pBuffer = &m_ExceptionInfoContent[0];
60+
dataChunk.FromMemory.BufferLength = static_cast<ULONG>(m_ExceptionInfoContent.size());
6761
}
6862
else
6963
{
@@ -117,6 +111,5 @@ class ServerErrorHandler : public REQUEST_HANDLER
117111
USHORT m_statusCode;
118112
USHORT m_subStatusCode;
119113
std::string m_statusText;
120-
BYTE* m_ExceptionInfoContent;
121-
int m_length;
114+
std::vector<byte> m_ExceptionInfoContent;
122115
};

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/StartupExceptionApplication.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ class StartupExceptionApplication : public InProcessApplicationBase
1616
HINSTANCE moduleInstance,
1717
BOOL disableLogs,
1818
HRESULT hr,
19-
BYTE* errorPageContent,
20-
int length)
19+
const std::vector<byte>& errorPageContent
20+
)
2121
: m_disableLogs(disableLogs),
2222
m_HR(hr),
2323
m_moduleInstance(moduleInstance),
2424
m_errorPageContent(errorPageContent),
25-
m_length(length),
2625
InProcessApplicationBase(pServer, pApplication)
2726
{
2827
}
@@ -31,16 +30,15 @@ class StartupExceptionApplication : public InProcessApplicationBase
3130

3231
HRESULT CreateHandler(IHttpContext* pHttpContext, IREQUEST_HANDLER** pRequestHandler)
3332
{
34-
*pRequestHandler = new ServerErrorHandler(*pHttpContext, 500, 30, "Internal Server Error", m_HR, m_moduleInstance, m_disableLogs, IN_PROCESS_RH_STATIC_HTML, m_errorPageContent, m_length);
33+
*pRequestHandler = new ServerErrorHandler(*pHttpContext, 500, 30, "Internal Server Error", m_HR, m_moduleInstance, m_disableLogs, IN_PROCESS_RH_STATIC_HTML, m_errorPageContent);
3534

3635
return S_OK;
3736
}
3837

3938
private:
40-
BYTE* m_errorPageContent;
39+
std::vector<byte> m_errorPageContent;
4140
BOOL m_disableLogs;
4241
HRESULT m_HR;
4342
HINSTANCE m_moduleInstance;
44-
int m_length;
4543
};
4644

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/dllmain.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ HINSTANCE g_hWinHttpModule;
2828
HINSTANCE g_hAspNetCoreModule;
2929
HANDLE g_hEventLog = NULL;
3030
bool g_fInProcessApplicationCreated = false;
31-
BYTE* g_errorPageContent;
32-
int g_errorPageLength;
31+
std::vector<byte> g_errorPageContent;
3332
HINSTANCE g_hServerModule;
3433

3534
HRESULT
@@ -130,7 +129,7 @@ CreateApplication(
130129
std::unique_ptr<InProcessOptions> options;
131130
THROW_IF_FAILED(InProcessOptions::Create(*pServer, pSite, *pHttpApplication, options));
132131
// Set the currently running application to a fake application that returns startup exceptions.
133-
auto pErrorApplication = std::make_unique<StartupExceptionApplication>(*pServer, *pHttpApplication, g_hServerModule, options->QueryDisableStartUpErrorPage(), hr, g_errorPageContent, g_errorPageLength);
132+
auto pErrorApplication = std::make_unique<StartupExceptionApplication>(*pServer, *pHttpApplication, g_hServerModule, options->QueryDisableStartUpErrorPage(), hr, g_errorPageContent);
134133

135134
RETURN_IF_FAILED(pErrorApplication->StartMonitoringAppOffline());
136135
*ppApplication = pErrorApplication.release();

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
#include "EventLog.h"
88

99
extern bool g_fInProcessApplicationCreated;
10-
extern BYTE* g_errorPageContent;
11-
extern int g_errorPageLength;
10+
extern std::vector<byte> g_errorPageContent;
1211
extern IHttpServer* g_pHttpServer;
1312

1413
//
@@ -512,9 +511,8 @@ EXTERN_C __MIDL_DECLSPEC_DLLEXPORT
512511
VOID
513512
http_set_startup_error_page_content(_In_ byte* errorPageContent, int length)
514513
{
515-
g_errorPageContent = new BYTE[length];
516-
g_errorPageLength = length;
517-
memcpy(g_errorPageContent, errorPageContent, length);
514+
g_errorPageContent.resize(g_errorPageContent.size() + length);
515+
memcpy(&g_errorPageContent[g_errorPageContent.size() - length], errorPageContent, length);
518516
}
519517

520518
// End of export

0 commit comments

Comments
 (0)