Skip to content

Commit 0edffb1

Browse files
authored
[NEWDEV] CHSourceDlgProc: Don't set CustomSearchPath member to stack allocated buffer (reactos#8447)
Fixes a crash when installing a driver from custom directory. Also move the combobox handling code to the PrepareFoldersToScan() and call it instead. CORE-20409
1 parent f6a86c1 commit 0edffb1

2 files changed

Lines changed: 21 additions & 23 deletions

File tree

dll/win32/newdev/newdev.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ PrepareFoldersToScan(
473473
DWORD CustomTextLength = 0;
474474
DWORD LengthNeeded = 0;
475475
LPWSTR Buffer;
476+
INT idx = (INT)SendMessageW(hwndCombo, CB_GETCURSEL, 0, 0);
476477

477478
/* Calculate length needed to store the search paths */
478479
if (IncludeRemovableDevices)
@@ -492,7 +493,8 @@ PrepareFoldersToScan(
492493
}
493494
if (IncludeCustomPath)
494495
{
495-
CustomTextLength = 1 + ComboBox_GetTextLength(hwndCombo);
496+
CustomTextLength = 1 + ((idx != CB_ERR) ?
497+
(INT)SendMessageW(hwndCombo, CB_GETLBTEXTLEN, idx, 0) : ComboBox_GetTextLength(hwndCombo));
496498
LengthNeeded += CustomTextLength;
497499
}
498500

@@ -526,7 +528,9 @@ PrepareFoldersToScan(
526528
}
527529
if (IncludeCustomPath)
528530
{
529-
Buffer += 1 + GetWindowTextW(hwndCombo, Buffer, CustomTextLength);
531+
Buffer += 1 + ((idx != CB_ERR) ?
532+
SendMessageW(hwndCombo, CB_GETLBTEXT, idx, (LPARAM)Buffer) :
533+
GetWindowTextW(hwndCombo, Buffer, CustomTextLength));
530534
}
531535
*Buffer = '\0';
532536

dll/win32/newdev/wizard.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -684,39 +684,33 @@ CHSourceDlgProc(
684684
case IDC_BROWSE:
685685
{
686686
BROWSEINFOW bi = { 0 };
687-
LPITEMIDLIST pidl;
687+
LPITEMIDLIST pidl = NULL;
688688
WCHAR Title[MAX_PATH];
689-
WCHAR CustomSearchPath[MAX_PATH] = { 0 };
690-
INT len, idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_COMBO_PATH, CB_GETCURSEL, 0, 0);
691689
LoadStringW(hDllInstance, IDS_BROWSE_FOR_FOLDER_TITLE, Title, _countof(Title));
692690

693-
if (idx == CB_ERR)
694-
len = GetWindowTextLengthW(GetDlgItem(hwndDlg, IDC_COMBO_PATH));
695-
else
696-
len = (INT)SendDlgItemMessageW(hwndDlg, IDC_COMBO_PATH, CB_GETLBTEXTLEN, idx, 0);
697-
698-
if (len < _countof(CustomSearchPath))
691+
if (PrepareFoldersToScan(DevInstData,
692+
FALSE,
693+
TRUE,
694+
GetDlgItem(hwndDlg, IDC_COMBO_PATH)))
699695
{
700-
if (idx == CB_ERR)
701-
GetWindowTextW(GetDlgItem(hwndDlg, IDC_COMBO_PATH), CustomSearchPath, _countof(CustomSearchPath));
702-
else
703-
SendDlgItemMessageW(hwndDlg, IDC_COMBO_PATH, CB_GETLBTEXT, idx, (LPARAM)CustomSearchPath);
696+
bi.hwndOwner = hwndDlg;
697+
bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_NONEWFOLDERBUTTON;
698+
bi.lpszTitle = Title;
699+
bi.lpfn = BrowseCallbackProc;
700+
bi.lParam = (LPARAM)DevInstData;
701+
pidl = SHBrowseForFolderW(&bi);
704702
}
705-
DevInstData->CustomSearchPath = CustomSearchPath;
706-
707-
bi.hwndOwner = hwndDlg;
708-
bi.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_NONEWFOLDERBUTTON;
709-
bi.lpszTitle = Title;
710-
bi.lpfn = BrowseCallbackProc;
711-
bi.lParam = (LPARAM)DevInstData;
712-
pidl = SHBrowseForFolderW(&bi);
703+
713704
if (pidl)
714705
{
715706
WCHAR Directory[MAX_PATH];
716707
IMalloc* malloc;
717708

718709
if (SHGetPathFromIDListW(pidl, Directory))
719710
{
711+
/* Remove previous item selection */
712+
SendDlgItemMessageW(hwndDlg, IDC_COMBO_PATH, CB_SETCURSEL, -1, 0);
713+
720714
/* Set the IDC_COMBO_PATH text */
721715
SetWindowTextW(GetDlgItem(hwndDlg, IDC_COMBO_PATH), Directory);
722716
}

0 commit comments

Comments
 (0)