Fix negative indexing in dex module. (#1730)

* 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 38af38fb8d.
This commit is contained in:
Wesley Shields
2022-06-16 17:41:18 +02:00
committed by GitHub
parent 811c20f2bf
commit 15b8de578e
+2 -2
View File
@@ -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.
@@ -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.