Skip to content

Commit

Permalink
Fix negative indexing in dex module. (#1730)
Browse files Browse the repository at this point in the history
* Fix negative indexing in dex module.

When attempting to call dex_get_integer() or dex_get_string() with a negative
index we would eventually land in the assert() at
https://github.com/VirusTotal/yara/blob/master/libyara/object.c#L497 failing.
Instead of doing that let's check for negative values before going any further,
which will at least allow the module to continue processing.

* YR_UNDEFINED is < 0 already. Simplify the logic when checking for negative index.

* Revert "YR_UNDEFINED is < 0 already. Simplify the logic when checking for negative index."

This reverts commit 38af38f.
  • Loading branch information
wxsBSD authored and plusvic committed Jun 30, 2022
1 parent da831c2 commit 9b4372f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libyara/modules/dex/dex.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static int64_t dex_get_integer(
const char* pattern,
int64_t index)
{
if (index == YR_UNDEFINED)
if (index == YR_UNDEFINED || index < 0)
return YR_UNDEFINED;

// Impose a reasonably large limit to table indexes.
Expand All @@ -434,7 +434,7 @@ static SIZED_STRING* dex_get_string(
const char* pattern,
int64_t index)
{
if (index == YR_UNDEFINED)
if (index == YR_UNDEFINED || index < 0)
return NULL;

// Impose a reasonably large limit to table indexes.
Expand Down

0 comments on commit 9b4372f

Please sign in to comment.