@@ -32,61 +32,39 @@ void print_help(const char *name) {
3232
3333
3434int main (int argc, char **argv) {
35- modsecurity::RulesSet * rules;
35+ std::unique_ptr< modsecurity::RulesSet> rules ( new modsecurity::RulesSet ()) ;
3636 char **args = argv;
37- rules = new modsecurity::RulesSet ();
3837 int ret = 0 ;
3938
4039 args++;
4140
4241 if (*args == NULL ) {
4342 print_help (argv[0 ]);
44- delete rules;
4543 return 0 ;
4644 }
4745
4846 while (*args != NULL ) {
4947 struct stat buffer;
50- std::string argFull (" " );
51- const char *arg = *args;
48+ std::string arg = (*args);
5249 std::string err;
5350 int r;
54- bool need_free = false ;
55-
56- if (argFull.empty () == false ) {
57- if (arg[strlen (arg)-1 ] == ' \" ' ) {
58- argFull.append (arg, strlen (arg)-1 );
59- goto next;
60- } else {
61- argFull.append (arg);
62- goto next;
63- }
64- }
6551
66- if (arg[0 ] == ' \" ' && argFull.empty () == true ) {
67- if (arg[strlen (arg)-1 ] == ' \" ' ) {
68- argFull.append (arg+1 , strlen (arg) - 2 );
69- } else {
70- argFull.append (arg+1 );
71- goto next;
72- }
73- }
52+ // strip arg from leading and trailing '"' chars
53+ arg.erase (arg.find_last_not_of (' \" ' )+1 );
54+ arg.erase (0 , arg.find_first_not_of (' \" ' ));
7455
75- if (argFull.empty () == false ) {
76- arg = strdup (argFull.c_str ());
77- need_free = true ;
78- argFull.clear ();
56+ if (arg.empty () == true ) {
57+ args++;
58+ continue ;
7959 }
8060
8161 std::cout << " : " << arg << " -- " ;
82- if (stat (arg, &buffer) == 0 ) {
83- r = rules->loadFromUri (arg);
62+ if (stat (arg. c_str () , &buffer) == 0 ) {
63+ r = rules->loadFromUri (arg. c_str () );
8464 } else {
85- r = rules->load (arg);
86- }
87- if (need_free == true && arg != nullptr ) {
88- free ((void *)arg);
65+ r = rules->load (arg.c_str ());
8966 }
67+
9068 if (r < 0 ) {
9169 err.assign (rules->m_parserError .str ());
9270 rules->m_parserError .str (" " );
@@ -97,12 +75,10 @@ int main(int argc, char **argv) {
9775 if (err.empty () == false ) {
9876 std::cerr << " " << err << std::endl;
9977 }
100- next:
78+
10179 args++;
10280 }
10381
104- delete rules;
105-
10682 if (ret < 0 ) {
10783 std::cout << " Test failed." << std::endl;
10884 } else {
0 commit comments