@@ -32,61 +32,39 @@ void print_help(const char *name) {
32
32
33
33
34
34
int main (int argc, char **argv) {
35
- modsecurity::RulesSet * rules;
35
+ std::unique_ptr< modsecurity::RulesSet> rules ( new modsecurity::RulesSet ()) ;
36
36
char **args = argv;
37
- rules = new modsecurity::RulesSet ();
38
37
int ret = 0 ;
39
38
40
39
args++;
41
40
42
41
if (*args == NULL ) {
43
42
print_help (argv[0 ]);
44
- delete rules;
45
43
return 0 ;
46
44
}
47
45
48
46
while (*args != NULL ) {
49
47
struct stat buffer;
50
- std::string argFull (" " );
51
- const char *arg = *args;
48
+ std::string arg = (*args);
52
49
std::string err;
53
50
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
- }
65
51
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 (' \" ' ));
74
55
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 ;
79
59
}
80
60
81
61
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 () );
84
64
} 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 ());
89
66
}
67
+
90
68
if (r < 0 ) {
91
69
err.assign (rules->m_parserError .str ());
92
70
rules->m_parserError .str (" " );
@@ -97,12 +75,10 @@ int main(int argc, char **argv) {
97
75
if (err.empty () == false ) {
98
76
std::cerr << " " << err << std::endl;
99
77
}
100
- next:
78
+
101
79
args++;
102
80
}
103
81
104
- delete rules;
105
-
106
82
if (ret < 0 ) {
107
83
std::cout << " Test failed." << std::endl;
108
84
} else {
0 commit comments