Skip to content

Commit

Permalink
Fix index out of bounds error in procmon (#1792)
Browse files Browse the repository at this point in the history
* Fix index out of bounds error in procmon

* Fix
  • Loading branch information
tklengyel authored May 15, 2024
1 parent e2594a0 commit 44662f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/plugins/procmon/privileges.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct LUID_AND_ATTRIBUTES
struct TOKEN_PRIVILEGES
{
uint32_t privilege_count;
struct LUID_AND_ATTRIBUTES privileges[1];
struct LUID_AND_ATTRIBUTES privileges[];
} __attribute__((packed));

std::pair<std::string, fmt::Aarg> stringify_privilege(struct LUID_AND_ATTRIBUTES& privilege);
Expand Down
20 changes: 9 additions & 11 deletions src/plugins/procmon/win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,17 +696,15 @@ static event_response_t adjust_privileges_token_cb(drakvuf_t drakvuf, drakvuf_tr
VMI_SUCCESS != vmi_read(vmi, &ctx, sizeof(struct TOKEN_PRIVILEGES), newstate, nullptr) ||
!newstate->privilege_count)
goto done;
if (newstate->privilege_count > 1)
{
auto count = newstate->privilege_count - 1;
auto size = sizeof(struct TOKEN_PRIVILEGES) + sizeof(struct LUID_AND_ATTRIBUTES) * count;
g_free(newstate);
newstate = (struct TOKEN_PRIVILEGES*)g_malloc0(size);
if (!newstate ||
VMI_SUCCESS != vmi_read(vmi, &ctx, size, newstate, nullptr) ||
!newstate->privilege_count)
goto done;
}

auto count = newstate->privilege_count;
auto size = sizeof(struct TOKEN_PRIVILEGES) + sizeof(struct LUID_AND_ATTRIBUTES) * count;
g_free(newstate);
newstate = (struct TOKEN_PRIVILEGES*)g_malloc0(size);

if (!newstate || VMI_SUCCESS != vmi_read(vmi, &ctx, size, newstate, nullptr) ||
!newstate->privilege_count)
goto done;

for (size_t i = 0; i < newstate->privilege_count; ++i)
privileges.push_back(stringify_privilege(newstate->privileges[i]));
Expand Down

0 comments on commit 44662f3

Please sign in to comment.