Skip to content

Commit 8b7890b

Browse files
committed
Fix performance issue with non-matching rules when no callback is provided.
As pointed out by Arnim Rupp (@2d4d) in VirusTotal#172, the fix in VirusTotal#175 was not complete as there's was no performance gain when the callback was not provided, which is the most common case.
1 parent 95702bb commit 8b7890b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

yara-python.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -789,12 +789,6 @@ int yara_callback(
789789

790790
int which = ((CALLBACK_DATA*) user_data)->which;
791791

792-
// If the rule doesn't match and the user has not specified that they want to
793-
// see non-matches then nothing to do here.
794-
if (message == CALLBACK_MSG_RULE_NOT_MATCHING && callback != NULL &&
795-
(which & CALLBACK_NON_MATCHES) != CALLBACK_NON_MATCHES)
796-
return CALLBACK_CONTINUE;
797-
798792
switch(message)
799793
{
800794
case CALLBACK_MSG_IMPORT_MODULE:
@@ -808,6 +802,14 @@ int yara_callback(
808802

809803
case CALLBACK_MSG_SCAN_FINISHED:
810804
return CALLBACK_CONTINUE;
805+
806+
case CALLBACK_MSG_RULE_NOT_MATCHING:
807+
// If the rule doesn't match and the user has not specified that they want
808+
// to see non-matches then there's nothing more to do and we return
809+
// CALLBACK_CONTINUE, keep executing the function if otherwise.
810+
811+
if ((which & CALLBACK_NON_MATCHES) != CALLBACK_NON_MATCHES)
812+
return CALLBACK_CONTINUE;
811813
}
812814

813815
// At this point we have handled all the other cases of when this callback

0 commit comments

Comments
 (0)