VirusTotal / yara

The pattern matching swiss knife
https://virustotal.github.io/yara/
BSD 3-Clause "New" or "Revised" License
8.26k stars 1.44k forks source link

No error checking when allocating memory in yara code #1865

Closed halihel closed 1 year ago

halihel commented 1 year ago

Describe the bug Crashes (exceptions) occur in Yara code in Low Memory situations. There are multiple places in Yara code that allocate code but do not check for allocation failure, which later on cause exceptions in Low Memory situations. (See usage of yr_malloc, yr_calloc, yr_realloc, yr_strdup, yr_strndup)

For example: In scanner.c:

new_scanner->matches = (YR_MATCHES*) yr_calloc( rules->num_strings, sizeof(YR_MATCHES));

Exception in _yr_scanner_clean_matches:

  memset(
      scanner->matches, 0,
      sizeof(YR_MATCHES) * scanner->rules->num_strings);

To Reproduce Test in Low Memory situations.

Expected behavior No exceptions

Please complete the following information: Issues are observed in current Yara master.

plusvic commented 1 year ago

Fixed in 52ed0fede12da44e2ac0c4117145a22431caf527. If you find more cases like this please let us know.