From b3ce9032f0a19eaab43c3bbccb3bfc63635292ae Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 22 Jun 2007 18:58:09 +0000 Subject: [PATCH] Don't assume that WM_DESTROY is the last message to be received by a window. Since the child windows are still alive and kicking by the time the parent receives WM_DESTROY, it's still possible to receive other messages after WM_DESTROY. If we free any window specific data when handling WM_DESTROY, we should reset the window data field as well, and check if we have a valid pointer when retrieving the window data field later. ticket: 5584 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19627 dc483132-0cff-0310-8789-dd5450dbe970 --- .../identity/plugins/krb4/krb4configdlg.c | 22 +++++- .../identity/plugins/krb4/krb4newcreds.c | 11 +++ .../identity/plugins/krb5/krb5configcc.c | 11 +++ .../identity/plugins/krb5/krb5configid.c | 10 +++ .../identity/plugins/krb5/krb5configids.c | 14 ++++ .../identity/plugins/krb5/krb5newcreds.c | 24 +++++++ .../sample/templates/credprov/config_id.c | 3 + .../sample/templates/credprov/config_ids.c | 3 + .../sample/templates/credprov/config_main.c | 6 +- .../sample/templates/credprov/credacq.c | 3 + src/windows/identity/ui/cfg_appear_wnd.c | 5 ++ src/windows/identity/ui/cfg_general_wnd.c | 5 ++ src/windows/identity/ui/cfg_identities_wnd.c | 7 ++ src/windows/identity/ui/cfg_notif_wnd.c | 9 +++ src/windows/identity/ui/cfg_plugins_wnd.c | 8 +++ src/windows/identity/ui/configwnd.c | 24 +++++++ src/windows/identity/ui/credwnd.c | 67 ++++++++++++++----- src/windows/identity/ui/htwnd.c | 49 ++++++++++---- src/windows/identity/ui/newcredwnd.c | 18 +++++ src/windows/identity/ui/notifier.c | 8 ++- src/windows/identity/ui/propertywnd.c | 10 ++- src/windows/identity/uilib/configui.c | 1 + 22 files changed, 282 insertions(+), 36 deletions(-) diff --git a/src/windows/identity/plugins/krb4/krb4configdlg.c b/src/windows/identity/plugins/krb4/krb4configdlg.c index 338cf7fa8..309bf542b 100644 --- a/src/windows/identity/plugins/krb4/krb4configdlg.c +++ b/src/windows/identity/plugins/krb4/krb4configdlg.c @@ -113,6 +113,9 @@ krb4_ids_config_proc(HWND hwnd, d = (k4_ids_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (HIWORD(wParam) == BN_CLICKED) { k4_ids_check_mod(hwnd, d); } @@ -122,6 +125,9 @@ krb4_ids_config_proc(HWND hwnd, d = (k4_ids_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (HIWORD(wParam) == WMCFG_APPLY) { k4_ids_write_params(hwnd, d); } @@ -131,7 +137,11 @@ krb4_ids_config_proc(HWND hwnd, d = (k4_ids_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); - PFREE(d); + if (d) { + PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) 0); + } + break; } @@ -297,6 +307,9 @@ krb4_id_config_proc(HWND hwnd, d = (k4_id_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (wParam == MAKEWPARAM(IDC_CFG_GETTIX, BN_CLICKED)) { int gettix = 0; @@ -321,7 +334,7 @@ krb4_id_config_proc(HWND hwnd, d = (k4_id_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); - if (!d) + if (d == NULL) break; if (HIWORD(wParam) == WMCFG_APPLY) { @@ -343,10 +356,12 @@ krb4_id_config_proc(HWND hwnd, d = (k4_id_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); - if (!d) + if (d == NULL) break; PFREE(d); + + SetWindowLongPtr(hwnd, DWLP_USER, 0); } break; } @@ -531,6 +546,7 @@ krb4_confg_proc(HWND hwnd, if (d) { PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) 0); } break; diff --git a/src/windows/identity/plugins/krb4/krb4newcreds.c b/src/windows/identity/plugins/krb4/krb4newcreds.c index c2d477e0e..9c200b618 100644 --- a/src/windows/identity/plugins/krb4/krb4newcreds.c +++ b/src/windows/identity/plugins/krb4/krb4newcreds.c @@ -389,6 +389,9 @@ INT_PTR CALLBACK k4_nc_dlg_proc(HWND hwnd, d = (k4_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + k4_update_data(d); if (LOWORD(wParam) == IDC_NCK4_OBTAIN) { @@ -404,6 +407,10 @@ INT_PTR CALLBACK k4_nc_dlg_proc(HWND hwnd, { d = (k4_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + + if (d == NULL) + break; + k4_handle_wmnc_notify(d, wParam, lParam); } break; @@ -413,9 +420,13 @@ INT_PTR CALLBACK k4_nc_dlg_proc(HWND hwnd, d = (k4_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + d->nct->aux = 0; PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } break; } diff --git a/src/windows/identity/plugins/krb5/krb5configcc.c b/src/windows/identity/plugins/krb5/krb5configcc.c index b2b498e68..13c5ac86b 100644 --- a/src/windows/identity/plugins/krb5/krb5configcc.c +++ b/src/windows/identity/plugins/krb5/krb5configcc.c @@ -354,6 +354,10 @@ k5_ccconfig_dlgproc(HWND hwnd, case WM_COMMAND: d = (k5_ccc_dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + + if (d == NULL) + break; + switch(wParam) { case MAKEWPARAM(IDC_CFG_ADD, BN_CLICKED): { @@ -543,15 +547,22 @@ k5_ccconfig_dlgproc(HWND hwnd, d = (k5_ccc_dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + k5_free_file_ccs(&d->work); k5_free_file_ccs(&d->save); PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); return TRUE; case KHUI_WM_CFG_NOTIFY: d = (k5_ccc_dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + switch(HIWORD(wParam)) { case WMCFG_APPLY: if (k5_ccc_get_mod(d)) { diff --git a/src/windows/identity/plugins/krb5/krb5configid.c b/src/windows/identity/plugins/krb5/krb5configid.c index b5af1c2b2..e730a4bb0 100644 --- a/src/windows/identity/plugins/krb5/krb5configid.c +++ b/src/windows/identity/plugins/krb5/krb5configid.c @@ -324,6 +324,9 @@ k5_id_tab_dlgproc(HWND hwnd, d = (k5_id_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == BN_CLICKED) k5_id_check_mod(hwnd, d); @@ -333,6 +336,9 @@ k5_id_tab_dlgproc(HWND hwnd, d = (k5_id_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (HIWORD(wParam) == WMCFG_APPLY) { k5_id_write_params(hwnd, d); } @@ -342,6 +348,9 @@ k5_id_tab_dlgproc(HWND hwnd, d = (k5_id_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + khui_tracker_kill_controls(&d->tc_life); khui_tracker_kill_controls(&d->tc_renew); @@ -349,6 +358,7 @@ k5_id_tab_dlgproc(HWND hwnd, kcdb_identity_release(d->ident); PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); break; } return FALSE; diff --git a/src/windows/identity/plugins/krb5/krb5configids.c b/src/windows/identity/plugins/krb5/krb5configids.c index 8d6afd473..4699f056a 100644 --- a/src/windows/identity/plugins/krb5/krb5configids.c +++ b/src/windows/identity/plugins/krb5/krb5configids.c @@ -221,6 +221,9 @@ k5_ids_tab_dlgproc(HWND hwnd, d = (k5_ids_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + if (HIWORD(wParam) == EN_CHANGE) { k5_ids_check_mod(d); } else if (HIWORD(wParam) == BN_CLICKED) { @@ -245,6 +248,10 @@ k5_ids_tab_dlgproc(HWND hwnd, case KHUI_WM_CFG_NOTIFY: d = (k5_ids_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + + if (d == NULL) + break; + if (HIWORD(wParam) == WMCFG_APPLY) { k5_ids_write_params(d); } @@ -254,6 +261,9 @@ k5_ids_tab_dlgproc(HWND hwnd, d = (k5_ids_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; + khui_tracker_kill_controls(&d->tc_life); khui_tracker_kill_controls(&d->tc_renew); khui_tracker_kill_controls(&d->tc_life_min); @@ -262,9 +272,13 @@ k5_ids_tab_dlgproc(HWND hwnd, khui_tracker_kill_controls(&d->tc_renew_max); PFREE(d); + + SetWindowLongPtr(hwnd, DWLP_USER, 0); + break; } return FALSE; } + diff --git a/src/windows/identity/plugins/krb5/krb5newcreds.c b/src/windows/identity/plugins/krb5/krb5newcreds.c index d2458fe50..b382096a0 100644 --- a/src/windows/identity/plugins/krb5/krb5newcreds.c +++ b/src/windows/identity/plugins/krb5/krb5newcreds.c @@ -122,6 +122,7 @@ k5_handle_wm_destroy(HWND hwnd, } PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); return TRUE; } @@ -184,6 +185,9 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return TRUE; + if (d->nc->subtype == KMSG_CRED_NEW_CREDS) { khui_tracker_reposition(&d->tc_lifetime); khui_tracker_reposition(&d->tc_renew); @@ -201,6 +205,9 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return TRUE; + if (d->nc->subtype == KMSG_CRED_PASSWORD) return TRUE; @@ -249,6 +256,10 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + + if (d == NULL) + return TRUE; + nc = d->nc; l = (khui_htwnd_link *) lParam; @@ -277,6 +288,9 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return TRUE; + nc = d->nc; khui_cw_find_type(nc, credtype_id_krb5, &nct); @@ -352,6 +366,8 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; kmq_post_sub_msg(k5_sub, KMSG_CRED, KMSG_CRED_DIALOG_NEW_IDENTITY, @@ -365,6 +381,8 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; if(!d->sync && d->nc->result == KHUI_NC_RESULT_PROCESS) { kmq_post_sub_msg(k5_sub, KMSG_CRED, @@ -382,6 +400,8 @@ k5_handle_wmnc_notify(HWND hwnd, d = (k5_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; msg = (wchar_t *) lParam; @@ -420,6 +440,8 @@ k5_handle_wm_notify(HWND hwnd, pnmh->code == IPN_FIELDCHANGED) { d = (k5_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return 0; SendDlgItemMessage(hwnd, IDC_NCK5_PUBLICIP, IPM_GETADDRESS, @@ -444,6 +466,8 @@ k5_handle_wm_command(HWND hwnd, k5_dlg_data * d; d = (k5_dlg_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; cid = LOWORD(wParam); notif = HIWORD(wParam); diff --git a/src/windows/identity/sample/templates/credprov/config_id.c b/src/windows/identity/sample/templates/credprov/config_id.c index 850016266..0fd08617b 100644 --- a/src/windows/identity/sample/templates/credprov/config_id.c +++ b/src/windows/identity/sample/templates/credprov/config_id.c @@ -88,6 +88,8 @@ config_id_dlgproc(HWND hwnd, case KHUI_WM_CFG_NOTIFY: d = (config_id_dlg_data *) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; if (HIWORD(wParam) == WMCFG_APPLY) { /* TODO: apply changes */ @@ -108,6 +110,7 @@ config_id_dlgproc(HWND hwnd, /* TODO: perform any other required uninitialization */ free(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } } break; diff --git a/src/windows/identity/sample/templates/credprov/config_ids.c b/src/windows/identity/sample/templates/credprov/config_ids.c index 8d6f0081a..ecc49b20c 100644 --- a/src/windows/identity/sample/templates/credprov/config_ids.c +++ b/src/windows/identity/sample/templates/credprov/config_ids.c @@ -72,6 +72,8 @@ config_ids_dlgproc(HWND hwnd, case KHUI_WM_CFG_NOTIFY: d = (config_ids_dlg_data *) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; if (HIWORD(wParam) == WMCFG_APPLY) { /* TODO: apply changes */ @@ -88,6 +90,7 @@ config_ids_dlgproc(HWND hwnd, /* TODO: Perform any additional uninitialization */ free (d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } break; } diff --git a/src/windows/identity/sample/templates/credprov/config_main.c b/src/windows/identity/sample/templates/credprov/config_main.c index 87a2a15fc..cf8061b81 100644 --- a/src/windows/identity/sample/templates/credprov/config_main.c +++ b/src/windows/identity/sample/templates/credprov/config_main.c @@ -71,6 +71,8 @@ config_dlgproc(HWND hwnd, { d = (config_main_dlg_data *) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; /* WMCFG_APPLY is the only notification we care about */ @@ -88,8 +90,10 @@ config_dlgproc(HWND hwnd, /* TODO: perform any other required uninitialization here */ - if (d) + if (d) { free(d); + SetWindowLongPtr(hwnd, DWLP_USER); + } break; } diff --git a/src/windows/identity/sample/templates/credprov/credacq.c b/src/windows/identity/sample/templates/credprov/credacq.c index cd8db44ee..a65686ea4 100644 --- a/src/windows/identity/sample/templates/credprov/credacq.c +++ b/src/windows/identity/sample/templates/credprov/credacq.c @@ -147,6 +147,8 @@ handle_wm_command(HWND hwnd, WPARAM wParam, LPARAM lParam) { struct nc_dialog_data * d; d = (struct nc_dialog_data *) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; /* TODO: handle WM_COMMAND */ return FALSE; @@ -165,6 +167,7 @@ handle_wm_destroy(HWND hwnd, WPARAM wParam, LPARAM lParam) { d->nct = NULL; free(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } /* TODO: Perform any additional uninitialization */ diff --git a/src/windows/identity/ui/cfg_appear_wnd.c b/src/windows/identity/ui/cfg_appear_wnd.c index c7e9abc25..be7c79fff 100644 --- a/src/windows/identity/ui/cfg_appear_wnd.c +++ b/src/windows/identity/ui/cfg_appear_wnd.c @@ -308,6 +308,8 @@ khm_cfg_appearance_proc(HWND hwnd, case WM_COMMAND: d = (dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (wParam == MAKEWPARAM(IDC_CFG_FONTS, CBN_SELCHANGE)) { LRESULT idx; @@ -417,11 +419,14 @@ khm_cfg_appearance_proc(HWND hwnd, DeleteObject(d->c_font_normal); PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } return TRUE; case KHUI_WM_CFG_NOTIFY: d = (dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (HIWORD(wParam) == WMCFG_APPLY) { write_params(d); diff --git a/src/windows/identity/ui/cfg_general_wnd.c b/src/windows/identity/ui/cfg_general_wnd.c index 1e92947f0..2716818b1 100644 --- a/src/windows/identity/ui/cfg_general_wnd.c +++ b/src/windows/identity/ui/cfg_general_wnd.c @@ -332,11 +332,14 @@ khm_cfg_general_proc(HWND hwnd, d = (dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); if (d) { PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); } return TRUE; case WM_COMMAND: d = (dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (HIWORD(wParam) == BN_CLICKED) { if (LOWORD(wParam) == IDC_CFG_SHOWLOG) { @@ -405,6 +408,8 @@ khm_cfg_general_proc(HWND hwnd, case KHUI_WM_CFG_NOTIFY: d = (dlg_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (HIWORD(wParam) == WMCFG_APPLY) { write_params(d); diff --git a/src/windows/identity/ui/cfg_identities_wnd.c b/src/windows/identity/ui/cfg_identities_wnd.c index d45288a3a..ebe61e14d 100644 --- a/src/windows/identity/ui/cfg_identities_wnd.c +++ b/src/windows/identity/ui/cfg_identities_wnd.c @@ -230,6 +230,8 @@ handle_cfg_notify(HWND hwnd, HWND hw; node = get_window_node(hwnd); + if (node == NULL) + return TRUE; if (HIWORD(wParam) == WMCFG_APPLY) { @@ -255,6 +257,8 @@ handle_notify(HWND hwnd, lpnm = (LPNMHDR) lParam; node = get_window_node(hwnd); + if (node == NULL) + return FALSE; if (lpnm->idFrom == IDC_CFG_TAB) { switch(lpnm->code) { @@ -864,11 +868,14 @@ khm_cfg_add_ident_proc(HWND hwnd, khui_cw_destroy_cred_blob(d->nc); PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); break; case KHUI_WM_NC_NOTIFY: d = (add_ident_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; switch(HIWORD(wParam)) { case WMNC_ADD_CONTROL_ROW: diff --git a/src/windows/identity/ui/cfg_notif_wnd.c b/src/windows/identity/ui/cfg_notif_wnd.c index 91650adb8..846d41714 100644 --- a/src/windows/identity/ui/cfg_notif_wnd.c +++ b/src/windows/identity/ui/cfg_notif_wnd.c @@ -282,6 +282,8 @@ khm_cfg_notifications_proc(HWND hwnd, case WM_COMMAND: { d = (notif_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (HIWORD(wParam) == BN_CLICKED) { refresh_data(hwnd, d); @@ -299,6 +301,9 @@ khm_cfg_notifications_proc(HWND hwnd, case WM_TIMER: { d = (notif_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; + KillTimer(hwnd, 1); check_for_modification(d); @@ -309,6 +314,8 @@ khm_cfg_notifications_proc(HWND hwnd, case WM_DESTROY: { d = (notif_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; khui_tracker_kill_controls(&d->tc_renew); khui_tracker_kill_controls(&d->tc_warn1); @@ -325,6 +332,8 @@ khm_cfg_notifications_proc(HWND hwnd, case KHUI_WM_CFG_NOTIFY: { d = (notif_data *) (DWORD_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (HIWORD(wParam) == WMCFG_APPLY) { write_params(d); diff --git a/src/windows/identity/ui/cfg_plugins_wnd.c b/src/windows/identity/ui/cfg_plugins_wnd.c index 6290d3703..92f1cc06b 100644 --- a/src/windows/identity/ui/cfg_plugins_wnd.c +++ b/src/windows/identity/ui/cfg_plugins_wnd.c @@ -371,6 +371,8 @@ khm_cfg_plugins_proc(HWND hwnd, d = (plugin_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; if (wParam == IDC_CFG_PLUGINS && (lpnm = (LPNMHDR) lParam) && @@ -426,6 +428,8 @@ khm_cfg_plugins_proc(HWND hwnd, d = (plugin_dlg_data *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + return FALSE; switch (wParam) { case MAKEWPARAM(IDC_CFG_ENABLE, BN_CLICKED): @@ -627,6 +631,9 @@ khm_cfg_plugins_proc(HWND hwnd, #ifdef DEBUG assert(d); #endif + if (d == NULL) + return TRUE; + for (i=0; in_info; i++) { #ifdef DEBUG assert(d->info[i]); @@ -637,6 +644,7 @@ khm_cfg_plugins_proc(HWND hwnd, } PFREE(d); + SetWindowLongPtr(hwnd, DWLP_USER, 0); khm_set_dialog_result(hwnd, 0); } diff --git a/src/windows/identity/ui/configwnd.c b/src/windows/identity/ui/configwnd.c index 49ebfe48e..14eeb15a1 100644 --- a/src/windows/identity/ui/configwnd.c +++ b/src/windows/identity/ui/configwnd.c @@ -142,6 +142,8 @@ cfgui_initialize_dialog(HWND hwnd) { HICON hicon; d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + return; /* create and fill the image list for the treeview */ @@ -241,6 +243,8 @@ cfgui_uninitialize_dialog(HWND hwnd) { HWND hwtv; d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + return; hwtv = GetDlgItem(hwnd, IDC_CFG_NODELIST); @@ -298,6 +302,9 @@ cfgui_activate_node(HWND hwnd, khui_config_node node) { HWND hwtv; d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + return; + hwtv = GetDlgItem(hwnd, IDC_CFG_NODELIST); hItem = (HTREEITEM) khui_cfg_get_param(node); @@ -636,6 +643,9 @@ cfgui_update_state(HWND hwnd, int idx; d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + return; + hwtv = GetDlgItem(hwnd, IDC_CFG_NODELIST); hItem = (HTREEITEM) khui_cfg_get_param(node); @@ -679,6 +689,9 @@ cfgui_dlgproc_generic(HWND hwnd, case WM_CTLCOLORSTATIC: d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + break; + return (BOOL)(DWORD_PTR) d->hbr_white; case WM_ERASEBKGND: @@ -689,6 +702,8 @@ cfgui_dlgproc_generic(HWND hwnd, RECT r_fill; d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + break; GetClientRect(hwnd, &r_client); SetRectEmpty(&r_logo); @@ -781,6 +796,9 @@ cfgui_dlgproc(HWND hwnd, cfgui_uninitialize_dialog(hwnd); d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + break; + khui_delete_bitmap(&d->kbmp_logo); DeleteObject(d->hbr_white); @@ -842,6 +860,9 @@ cfgui_dlgproc(HWND hwnd, case WM_CTLCOLORSTATIC: { d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + break; + return (BOOL)(DWORD_PTR) d->hbr_white; } /* implicit break */ @@ -878,6 +899,9 @@ cfgui_dlgproc(HWND hwnd, case WMCFG_SYNC_NODE_LIST: d = cfgui_get_wnd_data(hwnd); + if (d == NULL) + break; + cfgui_sync_node_list(d, hwnd); break; } diff --git a/src/windows/identity/ui/credwnd.c b/src/windows/identity/ui/credwnd.c index 50e6c4efc..b2a7a1f0b 100644 --- a/src/windows/identity/ui/credwnd.c +++ b/src/windows/identity/ui/credwnd.c @@ -1127,14 +1127,17 @@ cw_timer_proc(HWND hwnd, KillTimer(hwnd, idEvent); tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); - r = (khui_credwnd_row *) idEvent; - r->flags &= ~KHUI_CW_ROW_TIMERSET; + if (tbl == NULL) + return; + r = (khui_credwnd_row *) idEvent; nr = (int)(r - tbl->rows); if(nr < 0 || nr >= tbl->n_rows) return; + r->flags &= ~KHUI_CW_ROW_TIMERSET; + if(r->flags & KHUI_CW_ROW_CRED) { nflags = cw_get_buf_exp_flags(tbl, (khm_handle) r->data); @@ -3024,11 +3027,14 @@ cw_wm_destroy(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); - cw_save_view(tbl, NULL); + if (tbl) { + cw_save_view(tbl, NULL); - cw_unload_view(tbl); + cw_unload_view(tbl); - PFREE(tbl); + PFREE(tbl); + SetWindowLongPtr(hwnd, 0, 0); + } return DefWindowProc(hwnd, uMsg, wParam, lParam); } @@ -3051,6 +3057,8 @@ cw_wm_paint(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) BOOL has_dc = FALSE; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + goto _exit; if (wParam != 0) { /* we assume that if wParam != 0, then that contains a device @@ -3311,20 +3319,20 @@ cw_wm_size(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) khui_credwnd_tbl * tbl; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl) { + cw_update_extents(tbl, TRUE); - cw_update_extents(tbl, TRUE); - - GetClientRect(hwnd, &rect); + GetClientRect(hwnd, &rect); - if(tbl->hwnd_notif) { - SetWindowPos( - tbl->hwnd_notif, - tbl->hwnd_header, - rect.left, - tbl->header_height, - rect.right - rect.left, - tbl->cell_height * 4, - 0); + if(tbl->hwnd_notif) { + SetWindowPos(tbl->hwnd_notif, + tbl->hwnd_header, + rect.left, + tbl->header_height, + rect.right - rect.left, + tbl->cell_height * 4, + 0); + } } return DefWindowProc(hwnd, uMsg, wParam, lParam); } @@ -3335,6 +3343,9 @@ cw_wm_notify(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) khui_credwnd_tbl * tbl; LPNMHDR pnmh; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; + pnmh = (LPNMHDR) lParam; if(pnmh->hwndFrom == tbl->hwnd_header) { LPNMHEADER ph; @@ -3361,6 +3372,9 @@ cw_kmq_wm_dispatch(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) kmq_wm_begin(lParam, &m); + if (tbl == NULL) + goto _skip_message; + if(m->type == KMSG_CRED) { switch (m->subtype) { case KMSG_CRED_ROOTDELTA: @@ -3573,6 +3587,8 @@ cw_kmq_wm_dispatch(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ; } + _skip_message: + return kmq_wm_end(m, rv); } @@ -4027,6 +4043,8 @@ cw_wm_mouse(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) int nm_state,nm_row,nm_col; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; /* we are basically trying to capture events where the mouse is hovering over one of the 'hotspots'. There are two kinds of @@ -4276,6 +4294,9 @@ cw_wm_hscroll(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) int newpos; tbl = (khui_credwnd_tbl *) (LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; + GetClientRect(hwnd, &cr); dx = tbl->scr_left; @@ -4437,6 +4458,8 @@ cw_wm_vscroll(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) RECT cr; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; GetClientRect(hwnd, &cr); cr.top += tbl->header_height; @@ -4567,6 +4590,8 @@ cw_pp_ident_proc(HWND hwnd, case WM_COMMAND: s = (khui_property_sheet *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (s == NULL) + return 0; switch(wParam) { case MAKEWPARAM(IDC_PP_IDDEF, BN_CLICKED): @@ -4625,6 +4650,8 @@ cw_pp_ident_proc(HWND hwnd, lpp = (LPPSHNOTIFY) lParam; s = (khui_property_sheet *) (LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (s == NULL) + return 0; switch(lpp->hdr.code) { case PSN_APPLY: @@ -4794,6 +4821,8 @@ cw_properties(HWND hwnd) khui_context_get(&ctx); tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; if(ctx.scope == KHUI_SCOPE_NONE) { khui_context_release(&ctx); @@ -4946,6 +4975,8 @@ cw_wm_command(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) khui_credwnd_tbl * tbl; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; if(HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == KHUI_HTWND_CTLID) { @@ -5303,6 +5334,8 @@ cw_wm_contextmenu(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) khui_credwnd_tbl * tbl; tbl = (khui_credwnd_tbl *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (tbl == NULL) + return 0; GetWindowRect(hwnd, &r); diff --git a/src/windows/identity/ui/htwnd.c b/src/windows/identity/ui/htwnd.c index a65ceceee..0f951a4ae 100644 --- a/src/windows/identity/ui/htwnd.c +++ b/src/windows/identity/ui/htwnd.c @@ -642,6 +642,8 @@ static LRESULT htw_paint(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) int ext_height = 0; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + return 0; if(!GetUpdateRect(hwnd, &r, !(d->flags & KHUI_HTWND_TRANSPARENT))) return 0; @@ -945,6 +947,9 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, BOOL rv; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + return 0; + newtext = (wchar_t *) lParam; if(d->text) { @@ -978,21 +983,24 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, int i; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); - if(d->text) - PFREE(d->text); - d->text = 0; - - if(d->links) { - for(i=0;imax_links;i++) { - if(d->links[i]) - PFREE(d->links[i]); + if (d) { + if(d->text) + PFREE(d->text); + d->text = 0; + + if(d->links) { + for(i=0;imax_links;i++) { + if(d->links[i]) + PFREE(d->links[i]); + } + PFREE(d->links); } - PFREE(d->links); - } - clear_styles(d); + clear_styles(d); - PFREE(d); + PFREE(d); + SetWindowLongPtr(hwnd, 0, 0); + } } break; @@ -1004,6 +1012,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, RECT r; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + return FALSE; GetClientRect(hwnd, &r); hbr = GetSysColorBrush(COLOR_WINDOW); @@ -1040,6 +1050,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, break; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; if(d->active_link >= 0) { SetCursor(d->hc_hand); @@ -1053,6 +1065,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, khui_htwnd_data * d; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; d->flags |= KHUI_HTWND_FOCUS; @@ -1065,6 +1079,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, khui_htwnd_data * d; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; d->flags &= ~KHUI_HTWND_FOCUS; @@ -1077,6 +1093,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, khui_htwnd_data * d; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; d->md_link = d->active_link; @@ -1089,6 +1107,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, khui_htwnd_data * d; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; if(d->md_link == d->active_link && d->md_link >= 0) { /* clicked */ @@ -1109,6 +1129,8 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, RECT r; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; old_pos = new_pos = d->scroll_left; ext = d->ext_width; @@ -1194,6 +1216,9 @@ LRESULT CALLBACK khui_htwnd_proc(HWND hwnd, int nl; d = (khui_htwnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (d == NULL) + break; + p.x = GET_X_LPARAM(lParam) + d->scroll_left; p.y = GET_Y_LPARAM(lParam) + d->scroll_top; diff --git a/src/windows/identity/ui/newcredwnd.c b/src/windows/identity/ui/newcredwnd.c index 6c8ea6094..e4797d7e8 100644 --- a/src/windows/identity/ui/newcredwnd.c +++ b/src/windows/identity/ui/newcredwnd.c @@ -93,6 +93,8 @@ nc_common_dlg_proc(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, DWLP_USER); + if (d == NULL) + break; /* message sent by parent to notify us of something */ switch(HIWORD(wParam)) { @@ -1684,6 +1686,8 @@ nc_handle_wm_destroy(HWND hwnd, khm_del_dialog(hwnd); d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return TRUE; d->nc->ident_cb(d->nc, WMNC_IDENT_EXIT, NULL, 0, 0, 0); @@ -1701,6 +1705,7 @@ nc_handle_wm_destroy(HWND hwnd, d->dlg_main = NULL; PFREE(d); + SetWindowLongPtr(hwnd, CW_PARAM, 0); return TRUE; } @@ -1714,6 +1719,8 @@ nc_handle_wm_command(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return 0; switch(HIWORD(wParam)) { case BN_CLICKED: @@ -1885,6 +1892,8 @@ static LRESULT nc_handle_wm_moving(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return FALSE; nc_notify_types(d->nc, KHUI_WM_NC_NOTIFY, MAKEWPARAM(0, WMNC_DIALOG_MOVE), (LPARAM) d->nc, TRUE); @@ -1901,6 +1910,8 @@ static LRESULT nc_handle_wm_nc_notify(HWND hwnd, int id; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return FALSE; switch(HIWORD(wParam)) { @@ -2587,6 +2598,8 @@ static LRESULT nc_handle_wm_timer(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return FALSE; if (wParam == NC_TIMER_SIZER) { @@ -2702,6 +2715,9 @@ static LRESULT nc_handle_wm_notify(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return FALSE; + nmhdr = (LPNMHDR) lParam; if (nmhdr->code == TCN_SELCHANGE) { @@ -2752,6 +2768,8 @@ static LRESULT nc_handle_wm_help(HWND hwnd, khui_nc_wnd_data * d; d = (khui_nc_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, CW_PARAM); + if (d == NULL) + return FALSE; hlp = (HELPINFO *) lParam; diff --git a/src/windows/identity/ui/notifier.c b/src/windows/identity/ui/notifier.c index afc774912..f1df06992 100644 --- a/src/windows/identity/ui/notifier.c +++ b/src/windows/identity/ui/notifier.c @@ -2356,7 +2356,10 @@ alerter_wnd_proc(HWND hwnd, d = (alerter_wnd_data *)(LONG_PTR) GetWindowLongPtr(hwnd, NTF_PARAM); - destroy_alerter_wnd_data(d); + if (d) { + destroy_alerter_wnd_data(d); + SetWindowLongPtr(hwnd, NTF_PARAM, 0); + } return TRUE; } @@ -2446,6 +2449,8 @@ alert_bin_wnd_proc(HWND hwnd, #ifdef DEBUG assert(d); #endif + if (d == NULL) + break; if (in_printclient) { hdc = (HDC) wParam; @@ -2745,6 +2750,7 @@ alert_bin_wnd_proc(HWND hwnd, case WM_DESTROY: { /* nothing needs to be done here */ + SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); } return 0; } diff --git a/src/windows/identity/ui/propertywnd.c b/src/windows/identity/ui/propertywnd.c index 4255b481b..340684889 100644 --- a/src/windows/identity/ui/propertywnd.c +++ b/src/windows/identity/ui/propertywnd.c @@ -187,6 +187,9 @@ LRESULT CALLBACK khui_property_wnd_proc( case PW_WM_SET_RECORD: { child = (pw_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); + if (child == NULL) + break; + kcdb_buf_release(child->record); child->record = (khm_handle) lParam; kcdb_buf_hold(child->record); @@ -197,8 +200,11 @@ LRESULT CALLBACK khui_property_wnd_proc( case WM_DESTROY: { child = (pw_data *)(LONG_PTR) GetWindowLongPtr(hwnd, 0); - kcdb_buf_release(child->record); - PFREE(child); + if (child) { + kcdb_buf_release(child->record); + PFREE(child); + SetWindowLongPtr(hwnd, 0, 0); + } } break; diff --git a/src/windows/identity/uilib/configui.c b/src/windows/identity/uilib/configui.c index f2994d840..6f4f940a8 100644 --- a/src/windows/identity/uilib/configui.c +++ b/src/windows/identity/uilib/configui.c @@ -1081,6 +1081,7 @@ khui_cfg_free_dialog_data(HWND hwnd_dlg) { if (d) { PFREE(d); + SetWindowLongPtr(hwnd_dlg, DWLP_USER, 0); } return (d)?KHM_ERROR_SUCCESS: KHM_ERROR_NOT_FOUND; -- 2.26.2