Fix crash when clicking on tray icon after importing the first profile

When clicking on tray icon, menu items are deleted and then recreated.
Deletion uses o.num_config:

    for (i = 0; i < o.num_configs; i++)
        DestroyMenu(hMenuConn[i]);

Commit 8e4183f9 ("Add '--command import' command line option")
added BuildFileList() call which modifies o.num_configs
but doesn't touch menus. When clicking on tray icon after import,
abovementioned code attemps to access invalid item in hMenuConn array
and crashes when this is the first imported profile and hMenuConn is NULL.
In other DestryMenu is called with invalid argument.

Fix by recreating popup menus instead of just rescan file list -
this will first delete menus with correct o.num_config value.

Signed-off-by: Lev Stipakov <lev@openvpn.net>
pull/467/head
Lev Stipakov 2021-11-12 11:54:39 +02:00 committed by Selva Nair
parent 77e32fa676
commit a9f176224f
3 changed files with 4 additions and 3 deletions

4
misc.c
View File

@ -704,6 +704,6 @@ ImportConfigFile(const TCHAR* source)
} }
ShowTrayBalloon(LoadLocalizedString(IDS_NFO_IMPORT_SUCCESS), fileName); ShowTrayBalloon(LoadLocalizedString(IDS_NFO_IMPORT_SUCCESS), fileName);
/* rescan file list after import */ /* destroy popup menus, based on existing num_configs, rescan file list and recreate menus */
BuildFileList(); RecreatePopupMenus();
} }

2
tray.c
View File

@ -332,7 +332,7 @@ DestroyPopupMenus()
} }
/* Rescan config folders and recreate popup menus */ /* Rescan config folders and recreate popup menus */
static void void
RecreatePopupMenus(void) RecreatePopupMenus(void)
{ {
DestroyPopupMenus(); DestroyPopupMenus();

1
tray.h
View File

@ -45,6 +45,7 @@
#define IDM_CLEARPASSMENU (1 + IDM_PASSPHRASEMENU) #define IDM_CLEARPASSMENU (1 + IDM_PASSPHRASEMENU)
#define IDM_RECONNECTMENU (1 + IDM_CLEARPASSMENU) #define IDM_RECONNECTMENU (1 + IDM_CLEARPASSMENU)
void RecreatePopupMenus(void);
void CreatePopupMenus(); void CreatePopupMenus();
void OnNotifyTray(LPARAM); void OnNotifyTray(LPARAM);
void OnDestroyTray(void); void OnDestroyTray(void);