VirusTotal / yara

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

Validation error for rule_modifier in grammar.y #2018

Closed tibibyte closed 7 months ago

tibibyte commented 7 months ago

YARA accepts rules which use the rule modifiers 'private' and 'global' more than once per rule.

rule_modifiers
    : /* empty */                      { $$ = 0;  }
    | rule_modifiers rule_modifier     { $$ = $1 | $2; }
    ;

rule_modifier
    : _PRIVATE_      { $$ = RULE_FLAGS_PRIVATE; }
    | _GLOBAL_       { $$ = RULE_FLAGS_GLOBAL; }
    ;

To reproduce this error write a YARA rule like the one depicted below and run it with YARA and a sample. grafik

YARA should notify the user that the syntax is not valid according to the documentation by displaying a syntax error.

One possible solution would be to change the grammar in grammar.y like this.

rule_modifiers
    : /* empty */                      
    | rule_modifier_global rule_modifier_private
    ;

rule_modifier_global
    : /*empty */      
    | _GLOBAL_      
    ;

rule_modifier_private
    : /*empty */      
    | _PRIVATE_      
    ;
plusvic commented 7 months ago

This is a known issue (see: https://github.com/VirusTotal/yara-x#duplicate-rule-modifiers-are-not-accepted) that I haven't pay too much attention because it's relatively harmless.

Your solution is partially correct, but don't take into account that private and global can appear in arbitrary order. However the solution shouldn't be hard to implement. Would you volunteer for sending a pull request with the solution?

tibibyte commented 7 months ago

This is a known issue (see: https://github.com/VirusTotal/yara-x#duplicate-rule-modifiers-are-not-accepted) that I haven't pay too much attention because it's relatively harmless.

Your solution is partially correct, but don't take into account that private and global can appear in arbitrary order. However the solution shouldn't be hard to implement. Would you volunteer for sending a pull request with the solution?

Sure. I will send a pull request.

plusvic commented 7 months ago

Fixed in #2019