Skip to content

Commit

Permalink
fixed multiple npe
Browse files Browse the repository at this point in the history
  • Loading branch information
henrypp committed Aug 7, 2017
1 parent 00cf565 commit 43c050b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 29 deletions.
65 changes: 37 additions & 28 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2536,12 +2536,18 @@ VOID _app_notifyremove (const size_t idx)
{
ITEM_LOG* ptr = notifications.at (idx);

if (ptr->hicon)
DestroyIcon (ptr->hicon);
if (ptr)
{
if (ptr->hicon)
{
DestroyIcon (ptr->hicon);
ptr->hicon = nullptr;
}

SecureZeroMemory (ptr, sizeof (ITEM_LOG));
free (ptr);
ptr = nullptr;
SecureZeroMemory (ptr, sizeof (ITEM_LOG));
free (ptr);
ptr = nullptr;
}

notifications.erase (notifications.begin () + idx);
}
Expand All @@ -2562,7 +2568,7 @@ VOID _app_notifycommand (HWND hwnd, BOOL is_block)
hash = ptr->hash;

if (IsDlgButtonChecked (hwnd, IDC_DISABLENOTIFY_ID))
apps[ptr->hash].is_silent = true;
apps[hash].is_silent = true;

if (!is_block)
{
Expand Down Expand Up @@ -2607,50 +2613,53 @@ VOID _app_notifycommand (HWND hwnd, BOOL is_block)
// create rule
ITEM_RULE* rule_ptr = (ITEM_RULE*)malloc (sizeof (ITEM_RULE));

SecureZeroMemory (rule_ptr, sizeof (ITEM_RULE));
if (rule_ptr)
{
SecureZeroMemory (rule_ptr, sizeof (ITEM_RULE));

const size_t name_length = min (wcslen (rule), RULE_NAME_CCH_MAX) + 1;
const size_t path_length = min (wcslen (ptr->full_path), RULE_APPS_CCH_MAX) + 1;
const size_t name_length = min (wcslen (rule), RULE_NAME_CCH_MAX) + 1;
const size_t path_length = min (wcslen (ptr->full_path), RULE_APPS_CCH_MAX) + 1;

rule_ptr->name = (LPWSTR)malloc ((name_length + 1) * sizeof (WCHAR));
rule_ptr->rule = (LPWSTR)malloc ((rule_length + 1) * sizeof (WCHAR));
rule_ptr->apps = (LPWSTR)malloc ((path_length + 1) * sizeof (WCHAR));
rule_ptr->name = (LPWSTR)malloc ((name_length + 1) * sizeof (WCHAR));
rule_ptr->rule = (LPWSTR)malloc ((rule_length + 1) * sizeof (WCHAR));
rule_ptr->apps = (LPWSTR)malloc ((path_length + 1) * sizeof (WCHAR));

StringCchCopy (rule_ptr->name, name_length + 1, rule);
StringCchCopy (rule_ptr->rule, rule_length + 1, rule);
StringCchCopy (rule_ptr->apps, path_length + 1, ptr->full_path);
StringCchCopy (rule_ptr->name, name_length + 1, rule);
StringCchCopy (rule_ptr->rule, rule_length + 1, rule);
StringCchCopy (rule_ptr->apps, path_length + 1, ptr->full_path);

//rule_ptr->protocol = ptr->protocol8;
rule_ptr->dir = (ptr->direction == FWP_DIRECTION_IN) ? DirInbound : DirOutbound;
rule_ptr->is_block = false;
rule_ptr->is_enabled = false;
//rule_ptr->protocol = ptr->protocol8;
rule_ptr->dir = (ptr->direction == FWP_DIRECTION_IN) ? DirInbound : DirOutbound;
rule_ptr->is_block = false;
rule_ptr->is_enabled = false;

rule_id = rules_custom.size ();
rules_custom.push_back (rule_ptr);
rule_id = rules_custom.size ();
rules_custom.push_back (rule_ptr);
}
}
else
{
// modify rule
}

apps_rules[ptr->hash].push_back (rule_id);
apps_rules[hash].push_back (rule_id);
}
else
{
// allow entire app
apps[ptr->hash].is_enabled = true;
apps[hash].is_enabled = true;

_r_listview_setitemcheck (app.GetHWND (), IDC_LISTVIEW, _app_getposition (app.GetHWND (), ptr->hash), TRUE);
_r_listview_setitemcheck (app.GetHWND (), IDC_LISTVIEW, _app_getposition (app.GetHWND (), hash), TRUE);
}

SetEvent (config.install_evt);
}
else
{
// block entire app
//apps[ptr->hash].is_enabled = false;
//apps[hash].is_enabled = false;

//_r_listview_setitemcheck (app.GetHWND (), IDC_LISTVIEW, _app_getposition (app.GetHWND (), ptr->hash), FALSE);
//_r_listview_setitemcheck (app.GetHWND (), IDC_LISTVIEW, _app_getposition (app.GetHWND (), hash), FALSE);
}

_app_profilesave (app.GetHWND ());
Expand All @@ -2667,7 +2676,7 @@ VOID _app_notifycommand (HWND hwnd, BOOL is_block)

for (size_t i = 0; i < notifications.size (); i++)
{
ITEM_LOG* p = notifications.at (i);
ITEM_LOG const* p = notifications.at (i);

if (p && p->hash == hash)
{
Expand All @@ -2677,7 +2686,7 @@ VOID _app_notifycommand (HWND hwnd, BOOL is_block)

for (size_t i = 0; i < idx_array.size (); i++)
{
_app_notifyremove (idx_array.at (i));
_app_notifyremove (i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

// memory limitation
#define RULE_NAME_CCH_MAX 64
#define RULE_RULE_CCH_MAX 512
#define RULE_RULE_CCH_MAX 256
#define RULE_APPS_CCH_MAX 2048

// libs
Expand Down

0 comments on commit 43c050b

Please sign in to comment.