@@ -47,7 +47,7 @@ use std::{fmt, io, process};
47
47
use backend:: { TargetArch , TargetArchError } ;
48
48
use bincode:: Error as BincodeError ;
49
49
use common:: BpfProgram ;
50
- use compiler:: { Compiler , Error as FilterFormatError , Filter } ;
50
+ use compiler:: { Compiler , Error as FilterFormatError , JsonFile } ;
51
51
use serde_json:: error:: Error as JSONError ;
52
52
use utils:: arg_parser:: { ArgParser , Argument , Arguments as ArgumentsBag } ;
53
53
@@ -158,7 +158,7 @@ fn get_argument_values(arguments: &ArgumentsBag) -> Result<Arguments> {
158
158
} )
159
159
}
160
160
161
- fn parse_json ( reader : & mut dyn Read ) -> Result < HashMap < String , Filter > > {
161
+ fn parse_json ( reader : & mut dyn Read ) -> Result < JsonFile > {
162
162
serde_json:: from_reader ( reader) . map_err ( Error :: Json )
163
163
}
164
164
@@ -171,7 +171,7 @@ fn compile(args: &Arguments) -> Result<()> {
171
171
172
172
// transform the IR into a Map of BPFPrograms
173
173
let bpf_data: HashMap < String , BpfProgram > = compiler
174
- . compile_blob ( filters, args. is_basic )
174
+ . compile_blob ( filters. 0 , args. is_basic )
175
175
. map_err ( Error :: FileFormat ) ?;
176
176
177
177
// serialize the BPF programs & output them to a file
@@ -681,6 +681,25 @@ mod tests {
681
681
. to_string ( ) ;
682
682
let json_input = unsafe { json_input. as_bytes_mut ( ) } ;
683
683
assert ! ( parse_json( & mut json_input. as_ref( ) ) . is_err( ) ) ;
684
+
685
+ // duplicate filter keys
686
+ let mut json_input = r#"
687
+ {
688
+ "thread_1": {
689
+ "default_action": "trap",
690
+ "filter_action": "allow",
691
+ "filter": []
692
+ },
693
+ "thread_1": {
694
+ "default_action": "trap",
695
+ "filter_action": "allow",
696
+ "filter": []
697
+ }
698
+ }
699
+ "#
700
+ . to_string ( ) ;
701
+ let json_input = unsafe { json_input. as_bytes_mut ( ) } ;
702
+ assert ! ( parse_json( & mut json_input. as_ref( ) ) . is_err( ) ) ;
684
703
}
685
704
686
705
// test with correctly formed JSON
@@ -689,7 +708,7 @@ mod tests {
689
708
let mut json_input = "{}" . to_string ( ) ;
690
709
let json_input = unsafe { json_input. as_bytes_mut ( ) } ;
691
710
692
- assert_eq ! ( parse_json( & mut json_input. as_ref( ) ) . unwrap( ) . len( ) , 0 ) ;
711
+ assert_eq ! ( parse_json( & mut json_input. as_ref( ) ) . unwrap( ) . 0 . len( ) , 0 ) ;
693
712
694
713
// empty Filter
695
714
let mut json_input =
@@ -757,6 +776,7 @@ mod tests {
757
776
758
777
let mut v2: Vec < _ > = parse_json ( & mut json_input. as_ref ( ) )
759
778
. unwrap ( )
779
+ . 0
760
780
. into_iter ( )
761
781
. collect ( ) ;
762
782
v2. sort_by ( |x, y| x. 0 . cmp ( & y. 0 ) ) ;
0 commit comments