@@ -36,9 +36,8 @@ void print_help(const char *name) {
3636
3737
3838int main (int argc, char **argv) {
39- modsecurity::RulesSet *rules ;
39+ auto rules = std::make_unique< modsecurity::RulesSet>() ;
4040 char **args = argv;
41- rules = new modsecurity::RulesSet ();
4241 int ret = 0 ;
4342
4443 args++;
@@ -50,41 +49,26 @@ int main(int argc, char **argv) {
5049
5150 while (*args != NULL ) {
5251 struct stat buffer;
53- std::string argFull (" " );
54- const char *arg = *args;
52+ std::string arg = *args;
5553 std::string err;
5654 int r;
5755
58- if (argFull.empty () == false ) {
59- if (arg[strlen (arg)-1 ] == ' \" ' ) {
60- argFull.append (arg, strlen (arg)-1 );
61- goto next;
62- } else {
63- argFull.append (arg);
64- goto next;
65- }
66- }
67-
68- if (arg[0 ] == ' \" ' && argFull.empty () == true ) {
69- if (arg[strlen (arg)-1 ] == ' \" ' ) {
70- argFull.append (arg+1 , strlen (arg) - 2 );
71- } else {
72- argFull.append (arg+1 );
73- goto next;
74- }
75- }
56+ // strip arg from leading and trailing '"' chars
57+ arg.erase (arg.find_last_not_of (' \" ' )+1 );
58+ arg.erase (0 , arg.find_first_not_of (' \" ' ));
7659
77- if (argFull .empty () == false ) {
78- arg = strdup (argFull. c_str ()) ;
79- argFull. clear () ;
60+ if (arg .empty () == true ) {
61+ args++ ;
62+ continue ;
8063 }
8164
8265 std::cout << " : " << arg << " -- " ;
83- if (stat (arg, &buffer) == 0 ) {
84- r = rules->loadFromUri (arg);
66+ if (stat (arg. c_str () , &buffer) == 0 ) {
67+ r = rules->loadFromUri (arg. c_str () );
8568 } else {
86- r = rules->load (arg);
69+ r = rules->load (arg. c_str () );
8770 }
71+
8872 if (r < 0 ) {
8973 err.assign (rules->m_parserError .str ());
9074 rules->m_parserError .str (" " );
@@ -95,12 +79,10 @@ int main(int argc, char **argv) {
9579 if (err.empty () == false ) {
9680 std::cerr << " " << err << std::endl;
9781 }
98- next:
82+
9983 args++;
10084 }
10185
102- delete rules;
103-
10486 if (ret < 0 ) {
10587 std::cout << " Test failed." << std::endl;
10688 } else {
0 commit comments