Mask the elevated secrets when logging its command line.
Sean Hall committed
Sep 2, 2022 at 16:06 UTC
d6ced0b6c527dc853d7e116acb60ba8fde9859da
3 files changed
+27
-3
src/burn/engine/core.cpp
+24
-3
@@ -1612,6 +1612,16 @@ extern "C" HRESULT CoreParseCommandLine(
1612
1613
++i;
1614
1615
+ hr = MemEnsureArraySizeForNewItems(reinterpret_cast<LPVOID*>(&pInternalCommand->rgSecretArgs), pInternalCommand->cSecretArgs, 3, sizeof(int), 3);
1616
+ ExitOnFailure(hr, "Failed to ensure size for secret args.");
1617
+
1618
+ pInternalCommand->rgSecretArgs[pInternalCommand->cSecretArgs] = i;
1619
+ pInternalCommand->cSecretArgs += 1;
1620
+ pInternalCommand->rgSecretArgs[pInternalCommand->cSecretArgs] = i + 1;
1621
+ pInternalCommand->cSecretArgs += 1;
1622
+ pInternalCommand->rgSecretArgs[pInternalCommand->cSecretArgs] = i + 2;
1623
+ pInternalCommand->cSecretArgs += 1;
1624
+
1625
hr = ParsePipeConnection(argv + i, pCompanionConnection);
1626
if (FAILED(hr))
1627
{
@@ -1684,7 +1694,7 @@ extern "C" HRESULT CoreParseCommandLine(
1694
if (i + 3 >= argc)
1695
{
1696
fInvalidCommandLine = TRUE;
1687
- ExitOnRootFailure(hr = E_INVALIDARG, "Must specify the embedded name, token and parent process id.");
1697
+ ExitWithRootFailure(hr, E_INVALIDARG, "Must specify the embedded name, token and parent process id.");
1698
}
1699
1700
switch (pInternalCommand->mode)
@@ -1701,7 +1711,7 @@ extern "C" HRESULT CoreParseCommandLine(
1711
break;
1712
default:
1713
fInvalidCommandLine = TRUE;
1704
- ExitOnRootFailure(hr = E_INVALIDARG, "Multiple mode command-line switches were provided.");
1714
+ ExitWithRootFailure(hr, E_INVALIDARG, "Multiple mode command-line switches were provided.");
1715
}
1716
1717
++i;
@@ -2111,6 +2121,7 @@ static HRESULT GetSanitizedCommandLine(
2121
{
2122
HRESULT hr = S_OK;
2123
DWORD dwUnknownArgIndex = 0;
2124
+ DWORD dwSecretArgIndex = 0;
2125
BOOL fHidden = FALSE;
2126
LPWSTR sczSanitizedArgument = NULL;
2127
LPWSTR sczVariableName = NULL;
@@ -2118,6 +2129,8 @@ static HRESULT GetSanitizedCommandLine(
2129
LPWSTR* argv = pInternalCommand->argv;
2130
DWORD cUnknownArgs = pInternalCommand->cUnknownArgs;
2131
int* rgUnknownArgs = pInternalCommand->rgUnknownArgs;
2132
+ DWORD cSecretArgs = pInternalCommand->cSecretArgs;
2133
+ int* rgSecretArgs = pInternalCommand->rgSecretArgs;
2134
2135
for (int i = 0; i < argc; ++i)
2136
{
@@ -2148,7 +2161,7 @@ static HRESULT GetSanitizedCommandLine(
2161
if (fHidden)
2162
{
2163
hr = StrAllocFormatted(&sczSanitizedArgument, L"%ls=*****", sczVariableName);
2151
- ExitOnFailure(hr, "Failed to copy sanitized argument.");
2164
+ ExitOnFailure(hr, "Failed to copy sanitized unknown argument.");
2165
}
2166
}
2167
}
@@ -2156,6 +2169,14 @@ static HRESULT GetSanitizedCommandLine(
2169
// Remember command-line switch to pass off to BA.
2170
AppAppendCommandLineArgument(&pCommand->wzCommandLine, argv[i]);
2171
}
2172
+ else if (dwSecretArgIndex < cSecretArgs && rgSecretArgs[dwSecretArgIndex] == i)
2173
+ {
2174
+ ++dwSecretArgIndex;
2175
+ fHidden = TRUE;
2176
+
2177
+ hr = StrAllocString(&sczSanitizedArgument, L"*****", 0);
2178
+ ExitOnFailure(hr, "Failed to copy sanitized secret argument.");
2179
+ }
2180
2181
if (fHidden)
2182
{
src/burn/engine/core.h
+2
@@ -89,6 +89,8 @@ typedef struct _BURN_ENGINE_COMMAND
89
{
90
int argc;
91
LPWSTR* argv;
92
+ DWORD cSecretArgs;
93
+ int* rgSecretArgs;
94
DWORD cUnknownArgs;
95
int* rgUnknownArgs;
96
BOOL fInvalidCommandLine;
src/burn/engine/engine.cpp
+1
@@ -414,6 +414,7 @@ static void UninitializeEngineState(
414
AppFreeCommandLineArgs(pEngineState->internalCommand.argv);
415
}
416
417
+ ReleaseMem(pEngineState->internalCommand.rgSecretArgs);
418
ReleaseMem(pEngineState->internalCommand.rgUnknownArgs);
419
420
PipeConnectionUninitialize(&pEngineState->embeddedConnection);