Skip to content

Commit

Permalink
Initialize stack variables. check return code from shell lnk loading (#…
Browse files Browse the repository at this point in the history
…8712)

## References
* Commit f273aa679d4d9fb516678fc7ed5fc6495a8e8532 from os repository.

## PR Checklist
* [x] Closes #7650 
* [x] I work here.
* [x] Tests passed

## Detailed Description of the Pull Request / Additional comments
* We found and fixed this in November 2017, but I fumbled the replication and accidentally overwrote the commit. This digs it up from history and puts it back in our code.
* When the shortcut file cannot be read for whatever reason, we are setting the hotkey value to uninitialized data as we never initialize several members on the stack in this function. It just so happens that the one in the `dwHotkey` field is commonly `0x4c` or the letter `L` which is then sent into the window procedure to tell the OS to capture it as a global hotkey and foreground the `conhost.exe` that was started. We should realize the load failure and not set any hotkey at all and we should initialize the stack variables. This does both.

## Validation Steps Performed
* [x] Manual scenario running LNK file that cannot be loaded from customer report (make LNK to cmd.exe, make it inaccessible to conhost so it can't load/read it.)
* [x] Manual scenario with `mklink`'d link that makes the shortcut parser attempt to load (and fail because it isn't a LNK at all from #7650)
  • Loading branch information
miniksa committed Jan 6, 2021
1 parent a8b4044 commit 6b2ae62
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/interactivity/win32/SystemConfigurationProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ void SystemConfigurationProvider::GetSettingsFromLink(

CONSOLE_STATE_INFO csi = pLinkSettings->CreateConsoleStateInfo();
csi.LinkTitle = linkNameForCsi;
WCHAR wszShortcutTitle[MAX_PATH];
BOOL fReadConsoleProperties;
WCHAR wszShortcutTitle[MAX_PATH] = L"\0";
BOOL fReadConsoleProperties = FALSE;
WORD wShowWindow = pLinkSettings->GetShowWindow();
DWORD dwHotKey = pLinkSettings->GetHotKey();

int iShowWindow;
WORD wHotKey;
int iShowWindow = 0;
WORD wHotKey = 0;
NTSTATUS Status = ShortcutSerialization::s_GetLinkValues(&csi,
&fReadConsoleProperties,
wszShortcutTitle,
Expand All @@ -105,19 +104,22 @@ void SystemConfigurationProvider::GetSettingsFromLink(
&iShowWindow,
&wHotKey);

// Convert results back to appropriate types and set.
if (SUCCEEDED(IntToWord(iShowWindow, &wShowWindow)))
if (NT_SUCCESS(Status))
{
pLinkSettings->SetShowWindow(wShowWindow);
}
// Convert results back to appropriate types and set.
if (SUCCEEDED(IntToWord(iShowWindow, &wShowWindow)))
{
pLinkSettings->SetShowWindow(wShowWindow);
}

dwHotKey = wHotKey;
pLinkSettings->SetHotKey(dwHotKey);
dwHotKey = wHotKey;
pLinkSettings->SetHotKey(dwHotKey);

if (wszLinkTarget[0] != L'\0')
{
// guarantee null termination to make OACR happy.
wszLinkTarget[ARRAYSIZE(wszLinkTarget) - 1] = L'\0';
if (wszLinkTarget[0] != L'\0')
{
// guarantee null termination to make OACR happy.
wszLinkTarget[ARRAYSIZE(wszLinkTarget) - 1] = L'\0';
}
}

// if we got a title, use it. even on overall link value load failure, the title will be correct if
Expand Down

0 comments on commit 6b2ae62

Please sign in to comment.