Skip to content

Commit 90e0976

Browse files
Joshua McHenryJoshua McHenry
authored andcommitted
fix(bq_driver): stop empty dialog areas acting as a documentation link
Clicking a blank part of the DSN setup dialog or the Advanced Options dialog could open a browser at the BigQuery ODBC/JDBC drivers page. Both dialogs hit-test WM_LBUTTONDOWN against the documentation hyperlink's rectangle, but the CreateHyperlinkLabel calls that would create that control are currently commented out. GetDlgItem therefore returns NULL, GetClientRect(NULL, &rect) fails and leaves 'rect' holding whatever was on the stack, and PtInRect matches that uninitialised rectangle -- so clicks on unrelated parts of the dialog launch the browser. Which clicks match varies between runs, since it depends on stack contents. Bail out when the control does not exist or its rectangle cannot be read, and zero-initialise the rectangle so it can never hold garbage.
1 parent 704eeb0 commit 90e0976

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

google/cloud/odbc/bq_driver/internal/driver_adv_opt_form.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,20 @@ LRESULT CALLBACK AdvanceOptions::AdvanceOptProc(HWND hwnd, UINT u_msg,
639639
return 1; // Indicate we handled the background redraw
640640
}
641641
case WM_LBUTTONDOWN: {
642+
// Same guard as in driver_form.cc: the documentation hyperlink is not
643+
// created at present, so without checking for a NULL control the
644+
// uninitialised rect can swallow clicks anywhere on the dialog.
645+
HWND h_hyperlink = GetDlgItem(hwnd, kIdcHyperlink2);
646+
if (h_hyperlink == NULL) {
647+
break;
648+
}
649+
RECT rect = {};
650+
if (!GetClientRect(h_hyperlink, &rect)) {
651+
break;
652+
}
642653
POINT pt;
643654
GetCursorPos(&pt);
644655
ScreenToClient(hwnd, &pt);
645-
HWND h_hyperlink = GetDlgItem(hwnd, kIdcHyperlink2);
646-
RECT rect;
647-
GetClientRect(h_hyperlink, &rect);
648656
MapWindowPoints(h_hyperlink, hwnd, (LPPOINT)&rect, 2);
649657
if (PtInRect(&rect, pt)) {
650658
ShellExecute(NULL, "open", kBigQueryDocsURL, NULL, NULL, SW_SHOWNORMAL);

google/cloud/odbc/bq_driver/internal/driver_form.cc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,22 @@ LRESULT CALLBACK DriverForm::WindowProc(HWND hwnd, UINT u_msg, WPARAM w_param,
908908
return 1; // Indicate we handled the background redraw
909909
}
910910
case WM_LBUTTONDOWN: {
911+
// The documentation hyperlink is currently not created (see the
912+
// commented-out CreateHyperlinkLabel call), so GetDlgItem returns NULL.
913+
// Without these guards GetClientRect fails and leaves 'rect'
914+
// uninitialised, and clicks on empty parts of the dialog can fall inside
915+
// that garbage rectangle and launch a browser.
916+
HWND h_hyperlink = GetDlgItem(hwnd, kIdcHyperlink3);
917+
if (h_hyperlink == NULL) {
918+
break;
919+
}
920+
RECT rect = {};
921+
if (!GetClientRect(h_hyperlink, &rect)) {
922+
break;
923+
}
911924
POINT pt;
912925
GetCursorPos(&pt);
913926
ScreenToClient(hwnd, &pt);
914-
HWND h_hyperlink = GetDlgItem(hwnd, kIdcHyperlink3);
915-
RECT rect;
916-
GetClientRect(h_hyperlink, &rect);
917927
MapWindowPoints(h_hyperlink, hwnd, (LPPOINT)&rect, 2);
918928
if (PtInRect(&rect, pt)) {
919929
ShellExecute(NULL, "open", kBigQueryDocsURL, NULL, NULL, SW_SHOWNORMAL);

0 commit comments

Comments
 (0)