@@ -476,6 +476,11 @@ static int _yr_parser_write_string(
476
476
FAIL_ON_ERROR (_yr_compiler_store_string (compiler , identifier , & ref ));
477
477
478
478
string -> identifier = (const char * ) yr_arena_ref_to_ptr (compiler -> arena , & ref );
479
+ string -> rule_idx = compiler -> current_rule_idx ;
480
+ string -> idx = compiler -> current_string_idx ;
481
+ string -> fixed_offset = YR_UNDEFINED ;
482
+
483
+ compiler -> current_string_idx ++ ;
479
484
480
485
if (modifier .flags & STRING_FLAGS_HEXADECIMAL ||
481
486
modifier .flags & STRING_FLAGS_REGEXP ||
@@ -508,6 +513,14 @@ static int _yr_parser_write_string(
508
513
string -> length = (uint32_t ) literal_string -> length ;
509
514
string -> string = (uint8_t * ) yr_arena_ref_to_ptr (compiler -> arena , & ref );
510
515
516
+ if (modifier .flags & STRING_FLAGS_WIDE )
517
+ max_string_len = string -> length * 2 ;
518
+ else
519
+ max_string_len = string -> length ;
520
+
521
+ if (max_string_len <= YR_MAX_ATOM_LENGTH )
522
+ modifier .flags |= STRING_FLAGS_FITS_IN_ATOM ;
523
+
511
524
result = yr_atoms_extract_from_string (
512
525
& compiler -> atoms_config ,
513
526
(uint8_t * ) literal_string -> c_string ,
@@ -579,32 +592,14 @@ static int _yr_parser_write_string(
579
592
}
580
593
581
594
string -> flags = modifier .flags ;
582
- string -> rule_idx = compiler -> current_rule_idx ;
583
- string -> idx = compiler -> current_string_idx ;
584
- string -> fixed_offset = YR_UNDEFINED ;
585
595
586
596
// Add the string to Aho-Corasick automaton.
587
597
result = yr_ac_add_string (
588
- compiler -> automaton ,
589
- string ,
590
- compiler -> current_string_idx ,
591
- atom_list ,
592
- compiler -> arena );
598
+ compiler -> automaton , string , string -> idx , atom_list , compiler -> arena );
593
599
594
600
if (result != ERROR_SUCCESS )
595
601
goto cleanup ;
596
602
597
- if (modifier .flags & STRING_FLAGS_LITERAL )
598
- {
599
- if (modifier .flags & STRING_FLAGS_WIDE )
600
- max_string_len = string -> length * 2 ;
601
- else
602
- max_string_len = string -> length ;
603
-
604
- if (max_string_len <= YR_MAX_ATOM_LENGTH )
605
- string -> flags |= STRING_FLAGS_FITS_IN_ATOM ;
606
- }
607
-
608
603
atom = atom_list ;
609
604
c = 0 ;
610
605
@@ -616,8 +611,6 @@ static int _yr_parser_write_string(
616
611
617
612
(* num_atom ) += c ;
618
613
619
- compiler -> current_string_idx ++ ;
620
-
621
614
cleanup :
622
615
if (free_literal )
623
616
yr_free (literal_string );
0 commit comments